我正在创建一个用于客户访问的前端,并且在我的一个页面上,我要放置在标签旁边的输入小部件没有显示,我也没有遇到任何错误。
我将其放置在网格上并四处移动,我确保网格中没有其他东西
from tkinter import *
from tkinter import ttk
newCustomerPage = Tk()
newCustomerPage.geometry('400x172') #define the size of the window
newCustomerPage.overrideredirect(True) #removes the bar at the top of the window
windowWidth = newCustomerPage.winfo_reqwidth() #Place the window in the middle of the page
windowHeight = newCustomerPage.winfo_reqheight()
positionRight = int(newCustomerPage.winfo_screenwidth()/2.3 - windowWidth/2)
positionDown = int(newCustomerPage.winfo_screenheight()/3 - windowHeight/2)
newCustomerPage.geometry("+{}+{}".format(positionRight, positionDown))
print("New Customer Page set")
customerPageLabel = Label(newCustomerPage, text = "New Customer", font = ("Calibri", 25), padx = 110)#.pack(side = TOP, pady = 1)
customerPageLabel.grid(row = 0, column = 0)
newCustNameLabel = Label(newCustomerPage, text = 'Given Name:', font = ("Calibri", 12))#.pack(side = TOP, pady = 1)
newCustNameLabel.grid(row = 1, column = 0)
newCustNameEntry = Entry(newCustomerPage, width = 10)
newCustNameEntry.grid(row = 1, column = 1)
close = ttk.Button(newCustomerPage, text = 'Close', width = 20, command = newCustomerPage.destroy)#.pack(side = TOP, pady = 8)
close.grid(row = 2, column = 0)
页面打开并显示“新客户”,然后直接在页面中间的下方显示“给定名称:”,然后直接在其下方显示“关闭”按钮,该按钮功能正常,我希望输入框显示为'newCustNameLabel'的权限,但不是
答案 0 :(得分:0)
从文档中:
padx:该数量指定以屏幕为单位在从站的每一侧要保留多少水平外部填充。
因此,通过在网格#0列中设置padx=100
,您可以在两边应用100px的填充,这会将Entry
小部件推到屏幕之外。
您应该设置padx
的{{1}}而不是使用columnspan
,以便它可以跨越多于1列:
customerPageLabel
如果您希望列占用所有剩余空间,请为列设置权重:
customerPageLabel = Label(newCustomerPage, text = "New Customer", font = ("Calibri", 25))
customerPageLabel.grid(row = 0, column = 0, columnspan=2)