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

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

问题描述

我这里有一个包含两个按钮的程序.我正在尝试更改这些按钮的位置,以使它们之间留有空间,因为当前它们位于彼此的正下方.我该怎么做才能改变他们的位置?

I have a program here that has two buttons in it. I am trying to change the position of these buttons so that there is a space between them, because currently they are directly below each other. what should I do to change the position of them?

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()

任何帮助将不胜感激,谢谢!

any help would be gladly appreciated, thanks!

推荐答案

实际上,在上一学期,我也做了一些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)的值并根据您想要的位置放置小部件. strong>

See the bottom of the Page of the given link.The Place() method is defined with its proper arguments. I will prefer the Place() method over Pack() and Grid() because it works like CSS as we use in html, because it take the value of (width,height) and place your widget according to wherever you want.

如果您找到答案,将不胜感激.

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

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