/
ilya.petrash
/
SimplePyScripts
Обзор
Документация
Войти
/
ilya.petrash
/
SimplePyScripts
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
tkinter_examples/super_hello_world.py
50 строк
1 KB
gil9red
Refactoring. Using black code style
28 июн 2023, 13:13
28 июн 2023, 13:13
a351f0c
Код
Авторство
О чём код?
#!/usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = "ipetrash" # https://docs.python.org/3/library/tkinter.html import tkinter as tk from tkinter import messagebox def center_window(root, width=300, height=200): # get screen width and height screen_width = root.winfo_screenwidth() screen_height = root.winfo_screenheight() # calculate position x and y coordinates x = (screen_width / 2) - (width / 2) y = (screen_height / 2) - (height / 2) root.geometry("%dx%d+%d+%d" % (width, height, x, y)) def on_btn_1(): print("Hello World!") def on_btn_2(): text = "Hello World!" messagebox.showerror("Error", text) messagebox.showwarning("Warning", text) messagebox.showinfo("Information", text) app = tk.Tk() app.title("super_hello_world") center_window(app) label = tk.Label(app, text="Hello World!", font="Arial 16", fg="red") label.pack() btn_1 = tk.Button(app, text="Hello World!", command=on_btn_1) btn_1.pack() btn_2 = tk.Button(app, text="Click Me!", command=on_btn_2) btn_2.pack() app.mainloop()