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()被调用之前调用。 –
感谢您指出。 –