python 制作GUI页面以及多选框

Posted wukai66

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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()

 

以上是关于python 制作GUI页面以及多选框的主要内容,如果未能解决你的问题,请参考以下文章

如何的制作带有多选框的treeview?

网页制作中,做那种可多选的勾选框怎么做?

jQuery 获取多选框值,以及多选框中文的函数实践 by FungLeo

纯JavaScript 制作多选框逻辑实现

Python tkinter 多选框控件

antd多选框选项太多数据量太大出现页面卡顿怎么解决