标签:file ack 定义变量 ret 选项 column dialog open path
from tkinter import *
from tkinter import filedialog
from tkinter.filedialog import askdirectory
class QMainWindow():
def __init__(self, window):
self.window = window
# 定义变量,用户选择文件名的存放显示。tip:下面一定要加括号
self.input = StringVar()
self.radioflag = IntVar()
def showRadioButton(self):
"""
:return:
"""
def onclick():
flag = self.radioflag.get()
if flag == ‘1‘:
Radiobutton(self.window, text="单文件", variable=self.radioflag, value=1, command=onclick).pack()
Radiobutton(self.window, text="文件夹", variable=self.radioflag, value=2, command=onclick).pack()
return self.radioflag.get()
def showfile(self):
"""
选择单文件上传
:return:
"""
def selectFile(file):
# path_ = askdirectory() //选择路径
filename_ = filedialog.askopenfilename() # 选择文件
file.set(filename_)
Label(self.window, text="目标文件:").grid(row=1, column=0)
Entry(self.window, textvariable=self.input).grid(row=1, column=1)
Button(self.window, text="浏览", command=lambda: selectFile(self.input)).grid(row=1, column=2)
def showDirectory(self):
"""
选择整个文件夹上传,只会过滤file为xlsx的文件
:return:
"""
def selectPath(path):
path_ = askdirectory()
path.set(path_)
Label(self.window, text="目标路径:").grid(row=0, column=0)
Entry(self.window, textvariable=self.input).grid(row=0, column=1)
Button(self.window, text="浏览", command=lambda: selectPath(self.input)).grid(row=0, column=2)
# main方法
if __name__ == ‘__main__‘:
window = Tk()
window.geometry(‘300x300‘)
qw = QMainWindow(window)
# 弹出文件选择器,判断让用户选择抽取方式
button = qw.showRadioButton()
print(button)
window.mainloop()
--------------------
import tkinter
wuya = tkinter.Tk()
wuya.title("wuya")
wuya.geometry("300x200+10+20")
# 创建lable标签
lb = tkinter.Label(wuya,text=‘请选择您的性别:‘,fg=‘blue‘)
lb.pack()
# 定义选择后执行的函数
def func():
mg = ‘‘
mg += str(r.get())
text.delete(0.0,tkinter.END)
text.insert(‘insert‘,mg)
# 创建单选项
r = tkinter.IntVar()
radioflag = tkinter.IntVar()
male_select = tkinter.Radiobutton(wuya,text=‘男‘,value=1,variable=r,command=func)
male_select.pack()
female_select = tkinter.Radiobutton(wuya,text=‘女‘,value=2,variable=r,command=func)
female_select.pack()
tkinter.Radiobutton(wuya, text="单文件", variable=radioflag, value=1).pack()
tkinter.Radiobutton(wuya, text="文件夹", variable=radioflag, value=2).pack()
#
# 创建文本框
text = tkinter.Text(wuya,width=30,height=3)
text.pack()
wuya.mainloop()
标签:file ack 定义变量 ret 选项 column dialog open path
原文地址:https://www.cnblogs.com/zhangwensi/p/11460774.html