简体   繁体   English

Tkinter如何在窗口中间制作按钮

[英]Tkinter How To Make Button In Middle of Window

I want to make two buttons that are in the middle of the page - meaning one on top of the other with the same x-coordinates but the y-coordinates would have to be just outside the centre so that it would look proportionally correct 我想在页面中间创建两个按钮-意思是一个按钮在另一个按钮的顶部具有相同的x坐标,但y坐标必须恰好在中心之外,这样才能按比例正确显示

Code: [ This is what I have got so far ] 代码: [这是到目前为止我得到的]

from tkinter import *

class Window:
    def __init__(self, master):

        self.signup_button = Button(master, text="Sign Up", width=6,height=2)
        self.login_button = Button(master, text="Login", width=6,height=2)

        self.signup_button.grid()
        self.login_button.grid()

root=Tk()
run=Window(root)
root.mainloop()

Also, How do they position everything in such an organised manner : 此外,他们如何以一种有条理的方式放置所有内容

他们的位置一切都很好吗?

not sure what exactly do you expect as result, but you can try to adjust padx and pady values: 不确定结果期望什么,但是您可以尝试调整padx和pady值:

self.signup_button.grid(row = 0, column = 0, padx=5, pady=5)
self.login_button.grid(row = 0, column = 1, padx=5, pady=5)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM