1
因此,我很難理解如何從一個類的另一個函數中訪問函數的變量值。如何在一個類中創建一個全局函數的變量?
import Tkinter as tk, tkFileDialog
class test:
def __init__(self):
root = tk.Tk()
song_button = tk.Button(root, text = 'Select Song', fg = 'blue', command = self.loadfile).pack()
#how do I access the value of filename now?
def loadfile(self):
filename = tkFileDialog.askopenfilename(filetypes=[("allfiles","*"),("pythonfiles","*.py")])
想要在初始化程序中訪問'filename'?這將在loadfile()被調用之前調用。 –
感謝您指出。 –