Я выделил жирным шрифтом те части, где, по моему мнению, возникает проблема. При запуске программа останавливается и ничего не делает, но продолжает работать. Это часть более крупного проекта по написанию кода сапера. Я поставил ### ЗДЕСЬ ### там, где возникает проблема. Взаимодействие с другими людьми
from tkinter import *
from tkinter import Canvas
from PIL import ImageTk, Image
from time import sleep
class ResizingCanvas(Canvas):
def __init__(self,parent,**kwargs):
Canvas.__init__(self,parent,**kwargs)
self.bind("<Configure>", self.on_resize)
self.height = self.winfo_reqheight()
self.width = self.winfo_reqwidth()
def on_resize(self,event):
# determine the ratio of old width/height to new width/height
wscale = float(event.width)/self.width
hscale = float(event.height)/self.height
self.width = event.width
self.height = event.height
# resize the canvas
self.config(width=self.width, height=self.height)
# rescale all the objects tagged with the "all" tag
self.scale("all",0,0,wscale,hscale)
class Minesweeper(Tk):
def __init__(self, master):
Tk.__init__(self)
fr = Frame(self)
fr.pack(fill=BOTH, expand=YES)
self.canvas = ResizingCanvas(fr, width=940, height=920, bg="black", highlightthickness=0)
self.canvas.pack(fill=BOTH, expand=YES)
self.count = 0
self.start = 0
self.newWindow = Toplevel(self.master) ####HERE###
self.app = Control(self.newWindow) ####HERE###
self.title("MineSweeper")
x1 = 20
y1 = 20
x2 = 80
y2 = 80
self.block_pic = PhotoImage(file='C:/Users/akiva/OneDrive/Desktop/block.PNG')
self.flag_pic = PhotoImage(file='C:/Users/akiva/OneDrive/Desktop/flag.PNG')
for k in range(14):
for i in range(15):
self.canvas.create_rectangle(x1, y1, x2, y2, fill='white')
x1 += 60
x2 += 60
x1 = 20
x2 = 80
y1 += 60
y2 += 60
def shift_image(self):
if self.count == 0:
Tk.canvas.itemconfig(self.block_pic, image=self.flag_pic)
def end(self):
del self.block_pic
print("Game has ended")
self.after(2000, quit())
print("Game has ended")
self.start = 0
def frame(self):
self.start += 1
if self.start == 1:
x1 = 50
y1 = 50
for i in range(14):
for k in range(15):
self.canvas.create_image(x1, y1, image=self.block_pic)
x1 += 60
x1 = 50
y1 += 60
self.canvas.pack()
else:
print("Game has already started")
class Control:
def __init__(self, master):
self.master = master
self.frame = Frame(self.master)
**start_button = Button(self.frame, text="Start Game", command=Minesweeper(Tk).frame(),) ####HERE###
stop_button = Button(self.frame, text="End Game", command=Minesweeper(Tk).end()) ####HERE###
start_button.pack()
stop_button.pack()
self.quitButton = Button(self.frame, text='Quit', width=25, command=self.close_windows)
self.quitButton.pack()
self.frame.pack()
def close_windows(self):
self.master.destroy()
if __name__ == "__main__":
root = Tk
window = Minesweeper(root)
root.mainloop()
Traceback (most recent call last):
File "C:/Users/akiva/PycharmProjects/helloOpencv/Mine_sweeper.py", line 107, in <module>
window = Minesweeper(root)
File "C:/Users/akiva/PycharmProjects/helloOpencv/Mine_sweeper.py", line 37, in __init__
self.app = Control(self.newWindow)
File "C:/Users/akiva/PycharmProjects/helloOpencv/Mine_sweeper.py", line 86, in __init__
start_button = Button(self.frame, text="Start Game", command=Minesweeper(Tk).frame(),)
File "C:/Users/akiva/PycharmProjects/helloOpencv/Mine_sweeper.py", line 37, in __init__
self.app = Control(self.newWindow)
File "C:/Users/akiva/PycharmProjects/helloOpencv/Mine_sweeper.py", line 86, in __init__
start_button = Button(self.frame, text="Start Game", command=Minesweeper(Tk).frame(),)
File "C:/Users/akiva/PycharmProjects/helloOpencv/Mine_sweeper.py", line 29, in __init__
Tk.__init__(self)