@progerstas

Почему не работает функция?

Я хочу сделать, чтоб функция start_management вначале закрывало окно root, а потом создавало новое окно. Вот код:
# импорты
import time
from tkinter import *
from PIL import ImageTk
import pyautogui


# класс сокетов
class backend:

    def __init__(self):
        pass


    def send(self, msg):
        print(msg)


    def send_img(self, path):
        pass


class interface:

    def screen_management():

        def start_management():

            global root
            root.destroy()

            start = Toplevel()
            start.overrideredirect(1)
            start.state('zoomed')
            start.config(bg="khaki")
            start.bind("<KeyPress>", lambda event: start.destroy())


            image1 = ImageTk.PhotoImage(file="1.jpg")
            do = Label(start, image=image1)
            do.place(x = 0, y = 0, relwidth=1, relheight=1)

            start.mainloop()


        screen = Toplevel()
        # root.overrideredirect(1)
        screen_color = 'peachpuff'
        screen.state('zoomed')
        screen.config(bg=screen_color)

        image1 = ImageTk.PhotoImage(file="1.jpg")
        do = Label(screen, image=image1, width=300, height=300)
        do.place(x=150, y=100)

        image2 = PhotoImage(file="mng1.png")
        do_b = Button(screen, image=image2, command=start_management, activebackground=screen_color,background=screen_color)
        do_b["border"] = "0"
        do_b.place(x=165, y=415)

        image3 = PhotoImage(file="array.png")
        array = Button(screen, image=image3, command=lambda: screen.destroy(), activebackground=screen_color,background=screen_color)
        array["border"] = "0"
        array.place(x=25, y=100)

        screen.mainloop()


    root = Tk()
    # root.overrideredirect(1)
    root_color = 'moccasin'
    root.state('zoomed')
    root.config(bg=root_color)

    image2 = PhotoImage(file="mng.png")
    b1 = Button(root, image=image2, command=screen_management, activebackground=root_color,background=root_color)
    b1["border"] = "0"
    b1.place(x=50, y=100)

    image3 = PhotoImage(file="fun.png")
    b2 = Button(root, image=image3, command=screen_management, activebackground=root_color,background=root_color)
    b2["border"] = "0"
    b2.place(x=50, y=225)

    image4 = PhotoImage(file="mode.png")
    b3 = Button(root, image=image4, command=screen_management, activebackground=root_color,background=root_color)
    b3["border"] = "0"
    b3.place(x=50, y=350)

    image5 = PhotoImage(file="files.png")
    b4 = Button(root, image=image5, command=screen_management, activebackground=root_color,background=root_color)
    b4["border"] = "0"
    b4.place(x=50, y=475)

    root.mainloop()


a = interface()


И вот ошибка:
Traceback (most recent call last):
  File "rat.py", line 25, in <module>
    class shadow:
  File "rat.py", line 75, in shadow
    b1 = Button(root, image=image2, command=screen_management and root.destroy(), activebackground=root_color,background=root_color)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2032.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 2369, in __init__
    Widget.__init__(self, master, 'button', cnf, kw)
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.7_3.7.2032.0_x64__qbz5n2kfra8p0\lib\tkinter\__init__.py", line 2299, in __init__
    (widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: can't invoke "button" command: application has been destroyed


Помогите пожалуйста.
  • Вопрос задан
  • 192 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы