我不断收到TypeError:Template()不接受任何参数

时间:2020-01-30 16:56:55

标签: python python-3.x list

我正在尝试创建一个下拉菜单,该菜单返回一个可用于if语句的字符串。 我只希望创建标签,以便可以直观地看到所选选项的值,希望有人能够提供帮助。

为模板创建类

class Template:

  def _init_(self,version):
    self.version = version
    templateList.append(self)
    templateVersion.append(version)  

def selectVersion():
  for s in templateList:
    if s.version == selectedVersion.get():
      version.set(s.version)

templateList = []
templateVersion = []

Template("x1", "x1")
Template("x2", "x2")
Template("x3", "x3")
Template("x4", "x4")
Template("x5", "x5")
Template("x6", "x6")
Template("x7", "x7")
Template("c300", "c300")
Template("c400", "c400")
Template("c500", "c500")
Template("c600", "c600")
Template("c700", "c700")
Template("c800", "c800")

创建OptionMenu

selectedVersion = tk.StringVar()
selectedVersion.set(templateVersion[0])
#Template Menu
templateMenu = OptionMenu(frameTemp, selectedVersion, *templateVersion)
templateMenu.pack()

selectBtn = tk.Button(frameTemp, text = "Select", command = selectVersion)
selectBtn.pack()

version = tk.StringVar()

#label

tempLbl = Label(frameTemp, textvariable = version)
tempLbl.pack()

win.mainloop()

Traceback (most recent call last):
  File "c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\ptvsd_launcher.py", line 43, in <module>
    main(ptvsdArgs)
  File "c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\lib\python\old_ptvsd\ptvsd\__main__.py", line 432, in main
    run()
  File "c:\Users\User\.vscode\extensions\ms-python.python-2020.1.58038\pythonFiles\lib\python\old_ptvsd\ptvsd\__main__.py", line 316, in run_file
    runpy.run_path(target, run_name='__main__')
  File "C:\Python38\lib\runpy.py", line 263, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "C:\Python38\lib\runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "C:\Python38\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "c:\Users\User\Desktop\dropdown.py", line 38, in <module>
    Template("x1", "x1")
TypeError: Template() takes no arguments

0 个答案:

没有答案