igorich1376

Tkinter_plus_Button

Aug 22nd, 2024 (edited)
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. from tkinter import *
  2. #####################################
  3. def center(win):
  4.     """
  5.    centers a tkinter window
  6.    :param win: the main window or Toplevel window to center
  7.    """
  8.     win.update_idletasks()
  9.     width = win.winfo_width()
  10.     frm_width = win.winfo_rootx() - win.winfo_x()
  11.     win_width = width + 2 * frm_width
  12.     height = win.winfo_height()
  13.     titlebar_height = win.winfo_rooty() - win.winfo_y()
  14.     win_height = height + titlebar_height + frm_width
  15.     x = win.winfo_screenwidth() // 2 - win_width // 2
  16.     y = win.winfo_screenheight() // 2 - win_height // 2
  17.     win.geometry('{}x{}+{}+{}'.format(width, height, x, y))
  18.     win.deiconify()
  19. ######################################
  20. root = Tk()
  21. root.title('Пример кнопки')
  22. root.geometry('500x500')
  23. root.configure(background='green')
  24. center(root)
  25. #img = PhotoImage(file='gas-kvas-com-p-robot-belii-na-prozrachnom-fone-6.png')
  26. but_1 = Button(text='Нажми!', width=20,
  27.                #image=img,
  28.                height=2, font=('Arial','20'),
  29.                bg='cyan', fg='red', bd='10')
  30. but_1.place(x=83,y=320)
  31. #########################
  32. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment