gpt4 book ai didi

python - 如何在 Tkinter 中定位按钮?

转载 作者:行者123 更新时间:2023-11-28 22:31:26 35 4
gpt4 key购买 nike

我这里有一个程序,里面有两个按钮。我正在尝试将它们的位置更改为它们之间的空间,因为目前它们位于彼此的正下方。我应该怎么做才能改变按钮的位置?

def menu():
import tkinter
window=tkinter.Tk()
window.title('Lightning Parties')
window.configure(background='turquoise')
lbl=tkinter.Label(window, text='Welcome to Lightning Parties!', fg='purple', bg='turquoise', font=('comicsans', 14))
lbl.pack()

#here are the buttons
lbl=tkinter.Button(window, text='Returning customer options', fg='white', bg='purple', font=('comicsans', 12),command=combine_funcs(window.destroy, customer_login))
lbl.pack()

lbl=tkinter.Button(window, text='Register as a customer', fg='white', bg='purple', font=('comicsans', 12),command=combine_funcs(window.destroy, customer_details))
lbl.pack()

如有任何帮助,我们将不胜感激!

最佳答案

其实上学期我也做了一些Tkinter的应用,就是老师给我们的project。所以我去了一些 Python 教程网站,找到了三种将小部件放置在输出屏幕上的方法。三种方法是

 1. Pack()
2. Grid()
3. Place() #the best method over Pack() and Grid()

Place() 方法采用 x 和 y 形式的坐标。有关更多说明,请参阅此链接 https://www.tutorialspoint.com/python/python_gui_programming.htm

https://www.tutorialspoint.com/python/tk_place.htm

查看给定链接页面的底部。Place() 方法使用其适当的参数定义。我更喜欢 Place() 方法而不是 Pack() 和 Grid(),因为它的工作方式类似于我们在 html 中使用的 CSS,因为它采用 (width,height) 的值并根据您想要的位置放置小部件。

如果您找到答案,我们将不胜感激。

关于python - 如何在 Tkinter 中定位按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41574168/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com