python3 tkinter 桌面软件教程

效果图

 

""""brid布局"""
from tkinter import *
import tkinter.filedialog
from tkinter import scrolledtext        # 导入滚动文本框的模块
from tkinter.messagebox import *
import time

class TKMain():
    xin = Tk()
    path = StringVar()
    #路径赋值
    def selectPath(self):
        path_ = tkinter.filedialog.askopenfilename()
        self.path.set(path_)
    # 桌面
    def views(self):
        self.xin.geometry('400x400')  # 指定主框体大小
        self.xin.title('名称')  # 标题名
        Label(self.xin, text="编号").grid(row=1, column=0, sticky=E)

        self.number_id = tkinter.StringVar()
        self.number_id_entry = tkinter.Entry(self.xin)
        self.number_id_entry["textvariable"] = self.number_id
        self.number_id_entry.grid(row=1, column=1, sticky=E)

        Label(self.xin, text="文件").grid(row=3, column=0, sticky=E)
        #Entry(self.xin, stat="readonly", textvariable=self.path).grid(row=3, column=1, sticky=E)
        self.xls_path = tkinter.StringVar()
        self.xls_path_entry = tkinter.Entry(self.xin,stat="readonly")
        self.xls_path_entry["textvariable"] = self.path
        self.xls_path_entry.grid(row=3, column=1, sticky=E)
        Button(self.xin, text=" 选择 ", command=self.selectPath).grid(row=3, column=2, sticky=E)
        # 占位
        Label(self.xin, text="").grid(row=5, column=0)
        Button(self.xin, text=" 运行 ", command=self.validate).grid(row=6, column=1, sticky=E)
        Button(self.xin, text=" 停止 ").grid(row=6, column=2, sticky=E)
        # 占位
        Label(self.xin, text="").grid(row=7, column=0)
        # 滚动文本框
        scrolW = 50  # 设置文本框的长度
        scrolH = 18  # 设置文本框的高度
        self.text = scrolledtext.ScrolledText(self.xin, width=scrolW, height=scrolH, wrap=tkinter.WORD)
        self.text.grid(row=10, columnspan=8, sticky=tkinter.E)
        pass

    #验证事件
    def validate(self):
        is_validata = True;
        try:
            number_id_val = int(self.number_id.get());
            xls_path_val = self.path.get()
            if xls_path_val =="":
                is_validata = FALSE
            if number_id_val < 1:
                is_validata = FALSE
        except:
            is_validata = FALSE
        if is_validata == FALSE:
            for i in range(0,100):
                self.text.see(END)  # 一直查看文本的最后位置~
                time.sleep(0.5)
                self.text.insert('end', "验证不通过,请查看!" + str(i)+ "\r\n")
                self.text.update()#一直更新输出
                if i == 50 :
                    break
            print("验证不通过!")
        pass
    def app(self):
        self.views()
        mainloop()
def main():
    TKMain().app();
    pass;

if __name__ == "__main__":
    main()

 

posted @ 2018-05-27 04:42  freedom/cn  阅读(2591)  评论(0编辑  收藏  举报