zoukankan      html  css  js  c++  java
  • python 制作GUI页面以及多选框、单选框

    import osimport tkinter as tk
    from tkinter import filedialog
    from tkinter.scrolledtext import ScrolledText
    
    window = tk.Tk()
    window.title('华润万家门店导出')  # 标题
    window.geometry('600x500')  # 窗口尺寸
    
    file_path = ''
    
    contents = ScrolledText()
    contents.pack(side=tk.BOTTOM, expand=True, fill=tk.BOTH)
    # 输入文本框
    filename = tk.Entry()
    filename.pack(side=tk.LEFT, expand=True, fill=tk.X)
    
    
    # 打开文件
    def open_file():
        global file_path
        global on_hit
        file_path = filedialog.askopenfilename(title=u'选择文件', initialdir=(os.path.expanduser('H:/')))  # 这里打开文件 askdirectory(文件夹) 
        print('打开文件:', file_path)
        if file_path is not None:
            filename.insert(tk.INSERT, file_path)
            on_hit = True
    
    
    on_hit = False
    
    
    # 工作
    def work():
        global on_hit
        if on_hit:
            print('ok')
                elif res == '登陆密码不正确' or res == "用户名不正常":
                    print(res)
                    var1.set(res)
                    return
                else:
                    var1.set("下载完毕!")
                    return
    
    
    tk.Button(text='打开文件', command=open_file).pack(side=tk.LEFT)
    
    bt1 = tk.Button(window, text='开始运行', width=15, height=2, command=work)
    bt1.place(x=250, y=150)
    
    var1 = tk.StringVar()
    label = tk.Label(window, textvariable=var1, bg="blue", font=("Arial", 12), width=25, height=2)
    label.place(x=200, y=350)
    
    window.mainloop()  # 显示

    制作多选框

    import tkinter as tk
    
    # checkButton的内容,多选
    
    
    window = tk.Tk()
    window.title('华润万家门店导出')  # 标题
    window.geometry('600x500')  # 窗口尺寸
    
    # tx = tk.Text(window,variable="")
    one = tk.IntVar()
    two = tk.IntVar()
    three = tk.IntVar()
    
    ck_one = tk.Checkbutton(window, text="业务单据", variable=one, offvalue=0, onvalue=1)
    ck_two = tk.Checkbutton(window, text="销售日报", variable=two, offvalue=0, onvalue=1)
    ck_three = tk.Checkbutton(window, text="每日库存", variable=three, offvalue=0, onvalue=1)
    
    ck_one.pack()
    ck_two.pack()
    ck_three.pack()
    
    on_hit = False
    
    
    def work():
        print(one.get(), two.get(), three.get())  # 分别取值
        # global on_hit
        # if on_hit:
        print('ok')
    
    
    bt1 = tk.Button(window, text='开始运行', width=15, height=2, command=work)
    bt1.place(x=250, y=150)
    
    tk.mainloop()

     单选框

    def work():
        if on_hit:
            print(one.get())  # 取值 ,默认为0
            print(two.get())
            print(three.get())
            pass
    
    
    tk.Button(text='打开文件', command=open_file).pack(side=tk.LEFT)
    
    bt1 = tk.Button(window, text='开始运行', width=15, height=2, command=work)
    bt1.place(x=250, y=200)
    
    var1 = tk.StringVar()
    label = tk.Label(window, textvariable=var1, bg="blue", font=("Arial", 12), width=25, height=2)
    label.place(x=200, y=350)
    
    one = tk.IntVar()
    two = tk.IntVar()
    three = tk.IntVar()
  • 相关阅读:
    手冲咖啡的冲泡笔记(持续修正更新)
    Java学习笔记(4)--- 变量类型,修饰符
    程序员学做饭(1)---如何做好酱爆茄子
    Python爬虫入门教程 20-100 慕课网免费课程抓取
    Python爬虫入门教程 19-100 51CTO学院IT技术课程抓取
    Python爬虫入门教程 18-100 煎蛋网XXOO图片抓取
    Python爬虫入门教程 17-100 CSD*博客抓取数据
    Python爬虫入门教程 16-100 500px摄影师社区抓取摄影师数据
    Python爬虫入门教程 15-100 石家庄政民互动数据爬取
    Python爬虫入门教程 14-100 All IT eBooks多线程爬取
  • 原文地址:https://www.cnblogs.com/wukai66/p/13074361.html
Copyright © 2011-2022 走看看