tkinter TEXT


#!/usr/bin/env python
# -*- coding:utf-8 -*-
import Tkinter as tk
import ttk
import tkMessageBox as tkMB


class Application(tk.Tk):
    def __init__(self, master=None):
        tk.Tk.__init__(self, master)
        # super(self.__class__, self).__init__( master )
        self.title('test')
        label_frame_center = tk.LabelFrame(self)
        label_frame_center.grid()
        lfc_field_1 = tk.LabelFrame(label_frame_center)
        lfc_field_1.pack(fill="x")
        self.lfc_field_1_l = tk.Label(lfc_field_1, text="文件路径:", width=10)
        self.lfc_field_1_l.pack(fill="y", expand=0, side=tk.LEFT)
        self.lfc_field_1_b = tk.Button(lfc_field_1, text="清除:", width=10, height=1, command=self.clearText)
        self.lfc_field_1_b.pack(fill="none", expand=0, side=tk.RIGHT, anchor=tk.SE)

        ##########文本框与滚动条
        self.lfc_field_1_t_sv = tk.Scrollbar(lfc_field_1, orient=tk.VERTICAL)  # 文本框-竖向滚动条
        self.lfc_field_1_t_sh = tk.Scrollbar(lfc_field_1, orient=tk.HORIZONTAL)  # 文本框-横向滚动条

        self.lfc_field_1_t = tk.Text(lfc_field_1, height=15, yscrollcommand=self.lfc_field_1_t_sv.set,
                                     xscrollcommand=self.lfc_field_1_t_sh.set, wrap='none')  # 设置滚动条-不换行
        # 滚动事件
        self.lfc_field_1_t_sv.config(command=self.lfc_field_1_t.yview)
        self.lfc_field_1_t_sh.config(command=self.lfc_field_1_t.xview)

        # 布局
        self.lfc_field_1_t_sv.pack(fill="y", expand=0, side=tk.RIGHT, anchor=tk.N)
        self.lfc_field_1_t_sh.pack(fill="x", expand=0, side=tk.BOTTOM, anchor=tk.N)
        self.lfc_field_1_t.pack(fill="x", expand=1, side=tk.LEFT)

        # 绑定事件
        self.lfc_field_1_t.bind("<Control-Key-a>", self.selectText)
        self.lfc_field_1_t.bind("<Control-Key-A>", self.selectText)

        ##########文本框与滚动条end

        self.grid()
        self.createWidgets()

        label_frame_bottom = tk.LabelFrame(self)
        # label_frame_bottom.pack()

        pass

    # 文本全选
    def selectText(self, event):
        self.lfc_field_1_t.tag_add(tk.SEL, "1.0", tk.END)
        return 'break'  # 为什么要return 'break'

    # 文本清空
    def clearText(self):
        self.lfc_field_1_t.delete(0.0, tk.END)

    def createWidgets(self):
        self.quitButton = tk.Button(self, text='Quit', command=self.confirm)
        self.quitButton.grid()

    def confirm(self):
        result = str(self.lfc_field_1_t.get(1.0, tk.END))

        print result
        self.CI_LIST = []
        for i in result.split('\n'):
            tmp = []
            tmp = i.split(',')
            self.CI_LIST.append(tmp)
        print self.CI_LIST
        self.CI_LIST.pop(len(self.CI_LIST) - 1)
        msg = '是否添加SLA监控\n'
        for i in self.CI_LIST:
            tmp = 'CI : ' + i[0] + '      ip : ' + i[1] + '      CI描述 : ' + i[2]
            msg += tmp
        flag = tkMB.askokcancel("温馨提示", msg)
        if flag == True:
            print 'exe'


if __name__ == "__main__":
    app = Application()
    app.mainloop()

转载于:https://www.cnblogs.com/jian-pan/p/6654103.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值