您会注意到有一堆缺少的代码,它是从菜单中调用的所有游戏。我删除它,因为它很长,不需要我的问题。我的问题只与一个特定的功能,display_data
。当我从菜单中调用它时,matplot会在新窗口中打开并立即崩溃。我只是设置了下面的基本情节进行测试。有任何想法吗?matplot程序在运行时给出无响应的窗口
import matplotlib.pyplot as plt
def display_data():
plt.plot([1,2,4],[2,7,9])
plt.show()
# (6) Save Progress ------------------------------------------------------------
# (7) Load Data ----------------------------------------------------------------
# (8) Quit Game ----------------------------------------------------------------
def quit_game():
print('\nThank you for playing!')
# Main Menu --------------------------------------------------------------------
def menu():
calculation_game = print("\nEnter 1 to play 'Calculation'")
bin_reader = print("Enter 2 to play 'Binary Reader'")
trifacto = print("Enter 3 to play 'Trifacto'")
statistics = print("Enter 4 to view your statistics")
display_data = print("Enter 5 to display data")
save_game = print("Enter 6 to save your progress")
load_data = print("Enter 7 to load data")
quit_game = print("Enter 8 to quit the game")
def main_menu():
print('Welcome to BrainAge!')
main_record = []
user_input = ''
while user_input != '8':
menu()
user_input = input('\nWhat would you like to do? ')
if user_input == '1':
calculation_game()
if user_input == '2':
binary_reader_game()
if user_input == '3':
trifacto_game()
if user_input == '4':
display_statistics()
if user_input == '5':
display_data()
if user_input == '8':
quit_game()
main_menu()
它会立即崩溃吗?如果崩溃,告诉我们错误信息,如果它刚刚关闭,请查看已经回答的问题。 – Julien
它只是打开一个matplot窗口,它保持白色,并立即停止响应。没有错误信息,只是一个严重的崩溃。 –
是什么让你认为matplotlib崩溃?对我来说,它会*崩溃,但它会给出关于后端的错误,因为它应该如此。如果是这种情况,请在导入之前尝试添加'import matplotlib'和'matplotlib.use('Qt4Agg')'或类似的东西。随着这种变化,情节出现应该如此。另外,为什么在'menu()'函数中将所有这些局部变量定义为'None'? –