[英]Can't get labels and buttons to move to the correct position on grid using row and column
我是編程新手,對於課堂作業,我需要創建一個 tkinter Gui。 我必須將 2 個標簽、3 個按鈕和 2 個文本框排列到特定位置。 我通過網格輸入我想要的行或列,但它們沒有移動。
我試過一次做一個,但唯一的標簽沒有從左上角移動。 在所有不同的標簽和按鈕都被編碼后,我嘗試過這樣做,它們會輕微移動,或者不會移動到我想要的位置。
from tkinter import *
root = Tk()
root.title("Form 1")
root.geometry("300x300")
app = Frame(root)
app.grid()
lbl1 = Label(app, text = "Label1")
lbl1.grid(row=4, column=2)
lbl2 = Label(app, text = "Label2")
lbl2.grid(row=2, column=2)
lbl3 = Label(app, text = "Label3")
lbl3.grid(row=8, column=6)
bttn1 = Button(app, text = "Button 1")
bttn1.grid(row=20, column=1)
bttn2 = Button(app, text = "Button 2")
bttn2.grid(row=20, column=6)
bttn3 = Button(app, text = "Button 3")
bttn3.grid(row=20, column=11)
txt1 = Entry().grid()
txt2 = Entry().grid()
root.mainloop()
空行和空列的大小為零,除非您已使用rowconfigure
和/或columnconfigure
為它們提供最小或統一大小。 在這種情況下,第 1000 行將出現在第 0 行的正下方。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.