您會注意到有一堆缺少的代碼,它是從菜單中調用的所有遊戲。我刪除它,因爲它很長,不需要我的問題。我的問題只與一個特定的功能,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'? –