StudyRepo_Synergy/code_of_future/part1_basic/lesson10/app.py

66 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

"""
Модуль является результатом выполнения практической
домашней работы по теме "tkinter num2"
:copyright: Сергей Ванюшкин <pi3c@yandex.ru>
:git: https://git.pi3c.ru/pi3c/StudyRepo_Synergy.git
:license: MIT
2023г.
"""
from tkinter import *
class PyZen:
def __init__(self):
self.__root = Tk()
self.__root.title = "Определения Python"
self.__root.configure(bg="#00FFFF")
self.gen_zen()
self.label = Label(self.__root, text="Дзен Python")
self.text = Text(self.__root, wrap=WORD)
self.set_text()
self.btn_get = Button(
self.__root, text="Получить мудрость старейшин", command=self.get_shit
)
self.btn_exit = Button(self.__root, text="Выйти", command=self.exit)
self.label.pack(padx=20, pady=20)
self.text.pack(padx=20, pady=20)
self.btn_get.pack()
self.btn_exit.pack()
mainloop()
def gen_zen(self):
import contextlib
import io
with contextlib.redirect_stdout(echo := io.StringIO()):
import this
self.zen = (echo.getvalue()).split("\n")
def set_text(self, text=None):
self.text.delete("1.0", END)
if text is None:
self.text.insert("1.0", "Познаватель Дзена\n")
self.text.insert("2.0", "Нажмите кнопку и получите мудрость")
else:
self.text.insert("1.0", "Мудрость дня:\n")
self.text.insert("2.0", "\n")
self.text.insert("3.0", text + "\n\n")
self.text.insert("5.0", "\u00a9" + self.zen[0])
def get_shit(self):
import random
self.set_text(random.choice(self.zen[2:-1]))
def exit(self):
self.__root.destroy()
app = PyZen()