【发布时间】:2018-04-01 01:25:19
【问题描述】:
这是来自 Python3.6 和 Ubuntu 17.10
的 mi 代码它是用 Atom 编写的,将在 Jupyter 上实现 笔记本
from tkinter import *
from tkinter import ttk
这里开始错误
class Aplicacion():
def __init__(self):
self.root = Tk()
self.root.geometry('300x200')
self.root.resizable(width = False, height = False)
self.root.configure(bg = 'red')
self.root.title('Cachonerismo')
self.nombre = StringVar()
self.respuesta = StringVar()
self.txt = ttk.Entry(self.root,textvariable = self.nombre)
self.txt.pack(side = TOP)
self.txt1 = ttk.Entry(self.root, textvariable = self.respuesta)
self.txt1.pack(side = BOTTOM)
self.btn = ttk.Button(self.root, text = 'Mostrar', command = self.saluda).pack(side = LEFT)
self.bcl = ttk.Button(self.root, text='Cerrar', command = self.root.destroy).pack(side = RIGHT)
self.root.mainloop()
def saluda(self):
self.a = self.nombre.get(self)
self.respuesta.set(a)
app = Aplicacion()
这是我得到的错误
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.6/tkinter/__init__.py", line 1702, in __call__
return self.func(*args)
File "tkinterTest.py", line 23, in saluda
self.a = self.nombre.get(self)
TypeError: get() takes 1 positional argument but 2 were given
【问题讨论】:
-
将
StringVar更改为StringVar()。 -
谢谢,但现在我在 Tkinter 回调 Traceback 中收到此错误异常(最近一次调用最后一次):文件“/usr/lib/python3.6/tkinter/__init__.py”,第 1702 行,在 call return self.func(*args) File "tkinterTest.py", line 23, in saluda a = self.nombre.get(self) TypeError: get() 接受 1 个位置参数,但给出了 2 个
标签: python python-3.x class object tkinter