简体   繁体   中英

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

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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