码迷,mamicode.com
首页 > 编程语言 > 详细

python3 tkinter 桌面软件教程

时间:2018-05-27 10:48:02      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:效果   png   col   长度   python   pytho   分享图片   滚动   grid   

效果图

技术分享图片

 

""""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()

 

python3 tkinter 桌面软件教程

标签:效果   png   col   长度   python   pytho   分享图片   滚动   grid   

原文地址:https://www.cnblogs.com/wtcl/p/9095040.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!