3
我一直在环顾堆栈溢出的年龄试图找到答案,但我不能得到任何东西的工作,因此我问这个问题。我有一个带有三个按钮和一个标签的小程序,它们在一个网格中。我想知道如何不管大小或形状的按钮和标签将保持相对于框架相同。类似于如果我调整图像大小,一切都保持相同的大小。Python 3.6 - 根据帧大小调整Tkinter按钮的大小
这里是我的代码:
如果from tkinter import *
class Window(Frame): #All the stuff for the GUI
def __init__(self, master = None):
Frame.__init__(self, master)
self.master = master
self.init_window()
self.grid()
def init_window(self):
self.master.title("EncryptDecrypt")
self.pack(fill = BOTH, expand = 1)
quitButton = Button(self, text = "Quit", command = self.client_exit, width = 10, height = 5) #Quit Button
quitButton.grid(row = 0, column = 0, sticky = W)
encryptModeButton = Button(self, text = "Encrypt", command = lambda: self.execute("decrypted.txt", "encrypted.txt", 1, 0), width = 10, height = 5) #Encrypt Button
encryptModeButton.grid(row = 0, column = 1, sticky = W)
decryptModeButton = Button(self, text = "Decrypt", command = lambda: self.execute("encrypted.txt", "decrypted.txt", 0, 1), width = 10, height = 5) #Decrypt button
decryptModeButton.grid(row = 0, column = 2, sticky = W)
myLabel = Label(self, text = "Select The Action You Wish To Undertake", font = ("Purisa", 15))
myLabel.grid(row = 0, column = 3)
root = Tk()
root.geometry("610x80")
app = Window(root)
root.mainloop()
对不起,答案是显而易见的,我已经尝试pack()
我不太清楚你的要求。你是否在说,如果你调整窗户的大小,你希望一切都会增长? –
@BryanOakley是的,这是正确的 –