Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- #####################################
- def center(win):
- """
- centers a tkinter window
- :param win: the main window or Toplevel window to center
- """
- win.update_idletasks()
- width = win.winfo_width()
- frm_width = win.winfo_rootx() - win.winfo_x()
- win_width = width + 2 * frm_width
- height = win.winfo_height()
- titlebar_height = win.winfo_rooty() - win.winfo_y()
- win_height = height + titlebar_height + frm_width
- x = win.winfo_screenwidth() // 2 - win_width // 2
- y = win.winfo_screenheight() // 2 - win_height // 2
- win.geometry('{}x{}+{}+{}'.format(width, height, x, y))
- win.deiconify()
- ######################################
- root = Tk()
- root.title('Пример кнопки')
- root.geometry('500x500')
- root.configure(background='green')
- center(root)
- #img = PhotoImage(file='gas-kvas-com-p-robot-belii-na-prozrachnom-fone-6.png')
- but_1 = Button(text='Нажми!', width=20,
- #image=img,
- height=2, font=('Arial','20'),
- bg='cyan', fg='red', bd='10')
- but_1.place(x=83,y=320)
- #########################
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment