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