剛剛學習python並跳到tkinter。請幫忙。我得到以下錯誤:tkinter錯誤缺少參數:'self'
File "E:\Program Files\Python34\lib\tkinter\__init__.py", line 1533, in __call__
return self.func(*args)
TypeError: open() missing 1 required positional argument: 'self'
以下是我的Python代碼:
from tkinter.filedialog import askopenfilename
root = tkinter.Tk(className="Its a Full Mad Creation")
textPad = scrolledtext.ScrolledText(root, width=100, height=80) # creates text area
def __init__(self):
self.file_opt = options = {}
options['defaultextension'] = '.php'
options['filetypes'] = [('PHP files', '.php'), ('Javascript files', '.js'), ('HTML files', '.htm'), ('HTML files', '.html'), ('CSS files', '.css')]
def open(self):
file = tkinter.filedialog.askopenfile(parent=root, mode='rb', title='Select a php file', **self.file_opt)
if file != None:
contents = file.read()
textPad.insert('1.0', contents)
file.close()
完整的代碼是在這裏:http://pastie.org/private/swpihqat8eo063z2eo6fng
這個班在哪裏? – Rockybilly
http://pastie.org/private/swpihqat8eo063z2eo6fng –
其中是班級名稱? –