如何解决tkinter .packanchor =“ s”函数不起作用
首先,它向用户显示几个复选框,询问用户他们在哪里 想要将其放置在他们的屏幕上。
这些选项如下:东北,西北,东南和西南然后将其带到另一个函数(我测试过是否勾选了正确的var会导致1而不是0从而使vars2(西北),vars3(东北),vars4(东南)和vars5(东南)都可以工作,并将其中的位置分别设为nw,ne,se,sw,最后将其显示在屏幕上用户指定的位置。 / p>
我测试了几次,整个东北/西部地区似乎都可以使用,但是当它进入东南/西部地区时,它出现在与东北/西部地区相同的地方,而且不像预期的那样。我尝试了.grid()和.pack(),结果都是一样的。
但是就像Anurag Chandra所说的那样,可能是计算机规格标签太小了,这就是为什么它不起作用的原因,但是在南侧工作的最低要求是什么?
下面是完整的代码,不便之处,敬请谅解:
def allsa(wheres):
i=0
s="s"
alls = platform.uname()
addalls = ("System: ","Node: ","Release: ","Version: ","Machine: ","Processor: ")
als = len(alls)
alla = []
while i != als:
wha = alls[i]
what = addalls[i]
alla.append(what + wha)
i+=1
alla = ("\n").join(alla)
global Lebal
Lebal = Label(login,text=alla)
Lebal.pack(anchor= s)
##this works as well and defines what wheres will become so that it will appear exactly where the user wanted it to
def shoall(vars2,vars3,vars4,vars5):
global g
global askwhere
nw = vars2.get()
ne = vars3.get()
se = vars4.get()
sw = vars5.get()
total = sw+se+nw+ne
if total >1 or total ==0:
error.showerror("One","Please select one")
else:
g+=1
if nw ==1:
wheres = "nw"
askwhere.destroy()
allsa(wheres)
if ne ==1:
wheres = "ne"
askwhere.destroy()
allsa(wheres)
if se ==1:
wheres = "se"
askwhere.destroy()
allsa(wheres)
if sw==1:
wheres="sw"
askwhere.destroy()
allsa(wheres)
##This asks the user where they want to align the computer specifications hence wheres and when I check all these works and have the values which I expected so its not here
def specific():
global login
global g
if g==0:
global askwhere
askwhere=tk.Toplevel()
askwhere.title("Where to align it?")
askwhere.geometry("200x200")
ls = Label(askwhere,text="Where should we align this??").grid(row=0,column=1)
vars2 = IntVar()
Checkbutton(askwhere,text="north west?",variable=vars2).grid(row=1,column=1)
vars3 = IntVar()
Checkbutton(askwhere,text="north east?",variable=vars3).grid(row=2,column=1)
vars4 = IntVar()
Checkbutton(askwhere,text="south east",variable=vars4).grid(row=4,column=1)
vars5 = IntVar()
Checkbutton(askwhere,text="south west",variable=vars5).grid(row=6,column=1)
continues= partial(shoall,vars2,vars5)
continue_button = Button(askwhere,text="Continue?",command=continues).grid(row=8,column=1)
askwhere.mainloop()
else:
Lebal.pack_forget()
g-=1
解决方法
pack
的工作原理是沿着主服务器中空白空间的一侧分配空间。 side
选项采用“顶部”,“底部”,“左侧”或“右侧”之一。默认值为“ top”。因此,如果您未指定侧面,则该小部件将放置在空白处。
默认情况下,分配的空间将足够大以适合小部件。如果侧面是“顶部”或“底部”,则分配的空间将仅足够高以适合小部件,如果侧面是“左侧”或“右侧”,则分配的空间将仅足够宽以适合小部件。
anchor
选项指定窗口小部件在分配给它的空间内的位置。因此,如果仅指定anchor="s"
而未指定侧面或任何其他选项,则该小部件将出现在小部件中可用空间的顶部,并且{s}(南)的anchor
因为该空间刚好足以容纳小部件,所以没有任何作用。
如果您希望窗口小部件位于底部,则可以使用side="bottom"
:
如果您希望窗口小部件位于左下角,则需要结合使用anchor='w'
(向西)或anchor='sw'
(向西南),并将side
设置为“底部”
在定义标签时使用锚点
Lebal = Label(login,text=alla,anchor=wheres)
您可以指定东西方向
只有在标签足够大的情况下,南方才会起作用
,尝试将最后一行更改为
Lebal.pack(anchor=s)
所以基本上不是哪里,而是s
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。