我是使用Tkinter的新手,我已经遇到了这个问题,我想问题是列和行的配置,但这并没有改变。 这就是我得到的:
这是我的代码:
class Application(Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.grid()
self.grid_rowconfigure(0, weight=1)
self.grid_rowconfigure(1, weight=1)
self.grid_rowconfigure(2, weight=1)
self.grid_rowconfigure(3, weight=1)
self.grid_rowconfigure(4, weight=1)
self.grid_columnconfigure(0, weight=1)
self.grid_columnconfigure(1, weight=1)
self.create_widgets()
def create_widgets(self):
self.label = Label(self, justify=LEFT)
self.label["text"] = "Número:"
self.label.grid(column=0, row=0, sticky="e")
self.input = Entry(self)
self.input.grid(column=1, row=0, sticky="we")
self.baseValue = StringVar()
self.baseValue.set(basesNames[0]) # default value
self.label2 = Label(self)
self.label2["text"] = "Base:"
self.label2.grid(column=0, row=1, sticky="e")
self.menuNumber = ttk.Combobox(self, textvariable=self.baseValue)
self.menuNumber['values'] = basesNames
self.menuNumber.grid(column=1, row=1)
self.label2 = Label(self)
self.label2["text"] = "Base de resultado: "
self.label2.grid(column=0, row=2, sticky="e")
self.baseValueResult = StringVar()
self.baseValueResult.set(basesNames[0]) # default value
self.menuNumberResult = ttk.Combobox(self, textvariable=self.baseValueResult)
self.menuNumberResult['values'] = basesNames
self.menuNumberResult.grid(column=1, row=2)
self.convert = ttk.Button(self, text="Convertir", command=self.convertNumber)
self.convert.grid(row = 4, columnspan=2, sticky="sn")
self.result = Label(self)
self.result["text"] = "Your result is: "
self.result.grid(row=3, columnspan=2, sticky="ew")
root = Tk()
app = Application(master=root)
app.master.title("Conversor de bases")
app.master.maxsize(1000, 400)
app.mainloop()
此外,我检查了粘性参数是否必要,但这并没有改变
答案 0 :(得分:2)
您的窗口小部件包装在框架Application
中。因此,您还需要使框架扩展。
from tkinter import *
from tkinter import ttk
basesNames = ["a","b","c","d","e"]
class Application(Frame):
def __init__(self, master=None):
...
root = Tk()
app = Application(master=root)
app.master.title("Conversor de bases")
app.master.maxsize(1000, 400)
root.rowconfigure(0,weight=1)
root.columnconfigure(0,weight=1)
root.mainloop()