TelenkovDmitry 1 年間 前
コミット
74463f0f60
2 ファイル変更98 行追加0 行削除
  1. 50 0
      books/python/animals.py
  2. 48 0
      books/python/gui_1.py

+ 50 - 0
books/python/animals.py

@@ -0,0 +1,50 @@
+# Класс Mammal представляет млекопитающих
+
+class Mammal:
+
+    def __init__(self, species) -> None:
+        self.__species = species
+
+    def show_species(self):
+        print('Я -', self.__species)
+
+    def make_sound(self):
+        print('Гррррррр')
+
+class Dog(Mammal):
+
+    def __init__(self):
+        Mammal.__init__(self, 'собака')
+
+    def make_sound(self):
+        print('Гав-гав!')
+
+class Cat(Mammal):
+
+    def __init__(self) -> None:
+        Mammal.__init__(self, 'кот')
+
+    def make_sound(self):
+        print('Мяу!')
+
+#
+def show_mammal_info(creature):
+    if isinstance(creature, Mammal):
+        creature.show_species()
+        creature.make_sound()
+    else:
+        print('Это не млекопитающее!')
+
+
+def main():
+    animal = Mammal('обычное эивотное')
+    dog = Dog()
+    cat = Cat()
+
+    show_mammal_info(animal)
+    show_mammal_info(dog)
+    show_mammal_info(cat)
+    show_mammal_info('asdfsd')
+
+if __name__ == '__main__':
+    main()

+ 48 - 0
books/python/gui_1.py

@@ -0,0 +1,48 @@
+import tkinter
+from tkinter import messagebox
+
+class MyGUI:
+
+    def __init__(self):
+
+        # Создать виджет главного окна
+        self.main_window = tkinter.Tk()
+
+        # self.label1 = tkinter.Label(self.main_window, text='Hello world', 
+        #                             borderwidth=1, relief='solid')
+        
+        # self.label2 = tkinter.Label(self.main_window, text='This is my GUI',
+        #                             borderwidth=4, relief='raised')
+        
+        # self.label1.pack(ipadx=20, ipady=20)
+        # self.label2.pack(ipadx=20, ipady=20)
+
+        self.my_button = tkinter.Button(self.main_window, text='Нажми меня',
+                                        command=self.do_something)
+
+        self.quit_button = tkinter.Button(self.main_window, text='Exit',
+                                          command=self.main_window.destroy)
+
+        self.my_button.pack()
+        self.quit_button.pack()
+
+        # Показать заголовок
+        self.main_window.title('Мой первый GUI')
+
+        # Войти в главный цикл tkinter
+        tkinter.mainloop()
+
+    def do_something(self):
+        messagebox.showinfo(title=None, message='my message!')
+
+    
+
+def main():
+    my_gui = MyGUI()
+    # print(tkinter.__dict__)
+    # help(tkinter)
+
+
+if __name__ == '__main__':
+    main()
+