Пытаюсь прописать функционал обычного смартфона, включая его самого, используя Tkinter. Первым делом решил прописать включение/выключение телефона через двойное нажатие ЛКМ по кнопке питания (сверху). В теории всё должно работать так:
Двойное нажатие по кнопке питания > > Появление экрана загрузки с логотипом >> ЗАДЕРЖКА 2-5 СЕКУНД >> Открытие рабочего стола.
Пытался сделать через time.sleep(s) и root.after, но при включении смартфона вся программа зависает, и в итоге появляется только картинка рабочего стола, игнорируя отображение промежуточного экрана.
from tkinter import *
from PIL import Image, ImageTk
from random import randrange
from time import sleep
root = Tk()
root.geometry('500x500')
root.title('Смартфон')
root['bg'] = 'white'
c = Canvas(width=500, height=500, bg='white')
c.place(x=0,y=0)
def round_rectangle(x1, y1, x2, y2, radius=25, **kwargs):
points = [x1+radius, y1, x1+radius, y1,
x2-radius, y1, x2-radius, y1,
x2, y1,
x2, y1+radius, x2, y1+radius,
x2, y2-radius, x2, y2-radius,
x2, y2,
x2-radius, y2, x2-radius, y2,
x1+radius, y2, x1+radius, y2,
x1, y2,
x1, y2-radius, x1, y2-radius,
x1, y1+radius,x1, y1+radius,
x1, y1]
return c.create_polygon(points, **kwargs, smooth=True)
class Smartphone:
def __init__(self):
case = round_rectangle(50, 50, 250, 450, fill='gray', radius=25)
in_case = round_rectangle(52, 52, 248, 448, fill='white', radius=25)
#self.screen = c.create_rectangle(54,79,245,410, fill='black')
self.screen = Canvas(c, width=191, height=331, bg='black')
round_rectangle(110,60,190,63, radius=5, fill='gray')
home_button_case = c.create_oval(132,413,168,445, fill='lightgray')
self.home_button = c.create_oval(135,416,165,442, fill='white')
self.power_button = round_rectangle(200,47,225,52, radius=5, fill='gray')
self.smartphone_state = False
c.tag_bind(self.power_button, '<Double-Button-1>', self.download)
self.screen.place(x=52,y=77)
def download(self, event):
if not self.smartphone_state:
self.screen['bg'] = 'gray'
pillogo = Image.open(r'apple.ico')
apple = ImageTk.PhotoImage(pillogo)
image_sprite = self.screen.create_image(100,165, image=apple)
self.screen.image = apple
self.screen.after(5000,self.show_desktop())
def show_desktop(self):
self.screen['bg'] = 'white'
pillogo = Image.open(r'theme1.png')
theme = ImageTk.PhotoImage(pillogo)
image_sprite = self.screen.create_image(98,165, image=theme)
self.screen.image = theme
IPhone = Smartphone()
root.mainloop()