zoukankan      html  css  js  c++  java
  • TK

    # -*- coding: utf-8 -*-
    __author__ = 'Alon'
    __date__ = '2017/2/9 22:43'

    import Tkinter
    import tkFileDialog


    class MainFrame(Tkinter.Frame):
    def __init__(self, master=None):
    Tkinter.Frame.__init__(self, master)
    self.grid(row=0, column=0, sticky="nsew")
    self.dir_opt = Tkinter.StringVar()
    self.createFrame()

    def createFrame(self):
    label_frame_top = Tkinter.LabelFrame(self)
    label_frame_top.pack(fill="x")

    label_frame_center = Tkinter.LabelFrame(self)
    label_frame_center.pack(fill="x")

    label_frame_bottom = Tkinter.LabelFrame(self)
    label_frame_bottom.pack(fill="y")

    lfc_field_1 = Tkinter.LabelFrame(label_frame_top)
    lfc_field_1.pack(fill="x")

    lfc_field_2 = Tkinter.LabelFrame(label_frame_center)
    lfc_field_2.pack(fill="x")

    lfc_field_3 = Tkinter.LabelFrame(label_frame_bottom)
    lfc_field_3.pack(fill="y")

    self.lfc_field_1_2 = Tkinter.Label(lfc_field_1, text="文件路径:")
    self.lfc_field_1_2.pack(fill="x", expand=0, side=Tkinter.LEFT,anchor=Tkinter.E)

    self.lfc_field_1_3 = Tkinter.Entry(lfc_field_1,width=70,textvariable = self.dir_opt)
    self.lfc_field_1_3.pack(fill="x", expand=0, side=Tkinter.LEFT)

    self.lfc_field_1_4 = Tkinter.Button(lfc_field_1, text="选择",width=10, height=1,command=self.askdirectory)
    self.lfc_field_1_4.pack(fill="x", expand=0, side=Tkinter.RIGHT)

    self.lfc_field_1_l = Tkinter.Label(lfc_field_2, text="搜索文件:", width=10)
    self.lfc_field_1_l.pack(fill="y", expand=0, side=Tkinter.LEFT)

    self.lfc_field_1_b = Tkinter.Button(lfc_field_2, text="开始检查", width=10, height=1, command=self.insertlog)
    self.lfc_field_1_b.pack(fill="none", expand=0, side=Tkinter.RIGHT, anchor=Tkinter.SE)

    self.lfc_field_1_log = Tkinter.Text(lfc_field_3,)
    self.lfc_field_1_log.pack(fill="y", expand=0, side=Tkinter.RIGHT, anchor=Tkinter.SE)

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

    self.lfc_field_1_t = Tkinter.Text(lfc_field_2, height=10, 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=Tkinter.RIGHT, anchor=Tkinter.N)
    self.lfc_field_1_t_sh.pack(fill="x", expand=0, side=Tkinter.BOTTOM, anchor=Tkinter.N)
    self.lfc_field_1_t.pack(fill="x", expand=1, side=Tkinter.LEFT)

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


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



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

    pass

    #路径选择
    def askdirectory(self):

    """Returns a selected directoryname."""
    filepath = tkFileDialog.askdirectory()
    self.dir_opt.set(filepath)

    def insertlog(self):
    print 'dffd'
    self.lfc_field_1_log.insert(0.0,"sdsdsd ")


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

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


    def main():
    root = Tkinter.Tk()
    root.columnconfigure(0, weight=1)
    root.rowconfigure(0, weight=1)
    root.title("File check Tool")

    root.resizable(False, False)
    root.update() # update window ,must do
    curWidth = root.winfo_reqwidth() # get current width
    curHeight = root.winfo_height() # get current height
    scnWidth, scnHeight = root.maxsize() # get screen width and height
    # now generate configuration information
    tmpcnf = '%dx%d+%d+%d' % (curWidth*3, curHeight*3,
    (scnWidth - curWidth) / 2, (scnHeight - curHeight) / 3)

    root.geometry(tmpcnf)


    main_frame = MainFrame(root)
    main_frame.mainloop()


    if __name__ == "__main__":
    main()
    pass
  • 相关阅读:
    WPF & DirectShow 相关资料
    Com开发之回调
    COM开发之结构体
    WPF 提供了以下关键帧动画类[msdn]
    COM数据类型与托管类型对照
    图文并茂 简单 ATL COM开发
    WPF 动画笔记
    ShaderEffect 相关资料
    Visual \UIElemnt\FrameworkElement\Control
    关于WPF装饰器的笔记
  • 原文地址:https://www.cnblogs.com/aloneblog/p/6384816.html
Copyright © 2011-2022 走看看