如何在Tkinter中放置按钮? [英] How do I position buttons in Tkinter?

查看:164
本文介绍了如何在Tkinter中放置按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a program here that has two buttons in it. I am trying to change their position to be a space between them as currently they are directly below each other. What should I do to change the position of buttons?

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申请,是老师给我们的项目。因此,我去了一些Python教程网站,找到了三种在输出屏幕上放置小部件的方法。三种方法是

Actually in the previous semester I have also made some Tkinter application which is the project given by teacher to us. So I go to some tutorials website of Python and find three methods of placing the widgets on the output screen. The three methods are

 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

Place() method take the coordinates in the form of the x and y. See this link for more clarification 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)的值,并根据您想要的位置放置窗口小部件。

如果您找到答案,将非常感谢。

这篇关于如何在Tkinter中放置按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆