如何修复Tkinter上的“无法调用“按钮”命令:应用程序已被破坏”?

时间:2019-01-28 19:31:37

标签: python tkinter

错误,“无法调用“按钮”命令:应用程序已被破坏”,我不明白为什么。

我尝试将两个root.mainloop()分为两个函数,但是,这没有用。这是在学校玩的游戏。

### PATHOGEN EVOLUTION ###

### IMPORT ###

import tkinter as tk #Imports the module, 'tkinter', as 'tk'
import random as r #Imports the module, 'random', as 'r'
import time as t #Imports the module, 'time', as 't'

### FUNCTION ###

def game ():
    global startButton
    global tuberculosisImage
    startButton.destroy()
    root.mainloop()
    imageLoad()

def imageLoad ():
    pathogen = tk.Button(root, image = tuberculosisImage)
    pathogen.pack()
    root.mainloop()



### CODE ###

global startButton
global tuberculosisImage

root = tk.Tk() #Creates a root window named 'root'
root.geometry("1020x720") #Sets the window size of the window, 'root',    to 1020 x 720
root.title("Pathogen Evolution") #Changes the title of the window, 'root', to 'Pathogen Evolution'
root.iconbitmap("favicon(1).ico") #Changes the icon of the window, 'root'

startButton = tk.Button(root, text = "Start", border = 2, command = game)
tuberculosisImage = tk.PhotoImage(file = "pathogen1.gif")

startButton.pack()

root.mainloop() #Refreshes the window, 'root'

0 个答案:

没有答案