我不知道为什么但按钮没有显示 - 可能是一些简单的错误,但我没有看到它。请帮忙
如果有帮助我使用python 3
from tkinter import Tk, Label, Button, Entry, IntVar, END, W, E, filedialog, BOTH, Frame, LEFT
class Resizer(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.master = master
master.title("Resizer")
def askdir():
self.dir_opt = options = {}
options['initialdir'] = '~/'
options['mustexist'] = False
options['parent'] = root
options['title'] = 'This is a title'
filedialog.askdirectory(**self.dir_opt)
Button(self, text='askopenfile', command=askdir).pack()
root = Tk()
my_gui = Resizer(root)
root.mainloop()
答案 0 :(得分:0)
该按钮不可见,因为它的父级(my_gui
)不可见。您需要在pack
上使用place
,grid
或my_gui
来使其可见。例如:
my_gui = Resizer(root)
my_gui.pack(fill="both", expand=True)