在我的新程序中,我保持顯示相同的代碼行,所以我決定創建一個函數,並在需要時調用它。但我不斷收到一個錯誤,告訴我「我的功能沒有定義」。我是Python編程的新手,我無法想象它!Tkinter在類中調用函數
這是我的代碼:
import tkinter as tk
from tkinter import ttk
class GUI(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
#Window_Creation
scr_xloc = int(self.winfo_screenwidth()/2 - 800/2)
scr_yloc = int(self.winfo_screenheight()/2 - 600/2 - 30)
self.geometry("800x600+{}+{}".format(scr_xloc, scr_yloc))
self.minsize(width = 800, height = 600)
...
def Factorial_Calculation():
user_input = int(float(user_input))
import math
factorial_num = math.factorial(user_input)
self.Output_Box.delete("1.0", "end")
self.Output_Box.insert("1.0", str(user_input) + "! = " + str(factorial_num))
def x_Factorial_Loop(self, event):
global user_input
...
Factorial_Calculation()
您的縮進可能已關閉。你有混合的製表符和空格嗎? – bernie
你得到的確切完整的錯誤信息是什麼? –
NameError:名稱'Factorial_Calculation'未定義 –