问题描述
此代码将通过 tkinter
运行一个基本数据输入窗口,该窗口将保存用户的输入.当我运行代码并用鼠标单击提交按钮时,出现错误:
This code will run a basic data input window through tkinter
which will save the user's inputs. When i run the code and mouse click the Submit button I get the error:
print ("Información Adicional: {}".format(self.entry_name.get(1.0, "end")))
TypeError: get() takes 1 positional argument but 3 were given
这是代码:
import tkinter
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
class ImprintPlusApp:
def __init__(self, master):
self.frame_header = ttk.Frame(master)
self.frame_header.pack()
ttk.Label(self.frame_header, text = "Bienvenidos a Imprint Plus Manager")
self.frame_crearorden = ttk.Frame(master)
self.frame_crearorden.pack()
ttk.Label(self.frame_crearorden, text = "Nombre").grid(row = 0, column = 0, padx = 5)
ttk.Label(self.frame_crearorden, text = "Email").grid(row = 2, column = 0, padx = 5)
ttk.Label(self.frame_crearorden, text = "Numero Cel/Tel").grid(row = 4, column = 0, padx = 5)
ttk.Label(self.frame_crearorden, text = "Información Adicional").grid(row = 6, column = 0, padx = 5)
self.entry_name = ttk.Entry(self.frame_crearorden, width = 24)
self.entry_email = ttk.Entry(self.frame_crearorden, width = 24)
self.entry_numtc = ttk.Entry(self.frame_crearorden, width = 24)
self.entry_addinf = Text(self.frame_crearorden, width = 50, height = 10)
self.entry_name.grid(row = 0, column = 1, padx = 5)
self.entry_email.grid(row = 2, column = 1, padx = 5)
self.entry_numtc.grid(row = 4, column = 1, padx = 5)
self.entry_addinf.grid(row = 7, column = 0, columnspan = 2, padx = 5)
ttk.Button(self.frame_crearorden, text = "Submit", command = self.submit).grid(row = 8, column = 1,columnspan = 1, padx = 5)
ttk.Button(self.frame_crearorden, text = "Clear", command = self.clear).grid(row = 8, columnspan = 1, padx = 5)
def submit(self):
print ("Nombre: {}".format(self.entry_name.get()))
print ("Email: {}".format(self.entry_name.get()))
print ("Num Cel/Tel: {}".format(self.entry_name.get()))
print ("Información Adicional: {}".format(self.entry_name.get(1.0, "end")))
self.clear()
messagebox.showinfo(title = "Orden #", message = "Orden Guardada")
def clear(self):
self.entry_name.delete(0, "end")
self.entry_email.delete(0, "end")
self.entry_numtc.delete(0, "end")
self.entry_addinf.delete(1.0, "end")
def main():
root = Tk()
app = ImprintPlusApp(root)
root.mainloop()
if __name__ == '__main__':
main()
导致此错误的 get()
函数发生了什么情况?
What is happening with the get()
function that causes this error?
推荐答案
我不确定您要做什么,但这是导致错误的行,正如错误消息中明确指出的那样 -
I am not sure what you want to do, but this is the line causing the error, as clearly indicated by the error message -
print ("Información Adicional: {}".format(self.entry_name.get(1.0, "end")))
你需要做 -
print ("Información Adicional: {}".format(self.entry_name.get()))
因为 Tkinter.Entry 类的 get()
函数不接受任何参数.
Because Tkinter.Entry class' get()
function does not take any arguments.
还看代码,好像有逻辑问题-
Also looking at the code, there seems to be a logical issue -
def submit(self):
print ("Nombre: {}".format(self.entry_name.get()))
print ("Email: {}".format(self.entry_name.get()))
print ("Num Cel/Tel: {}".format(self.entry_name.get()))
print ("Información Adicional: {}".format(self.entry_name.get(1.0, "end")))
您不想从不同的 Entry
对象中获取每个条目吗?像这样 -
Don't you want to get each entry from different Entry
objects? Like this -
def submit(self):
print ("Nombre: {}".format(self.entry_name.get()))
print ("Email: {}".format(self.entry_email.get()))
print ("Num Cel/Tel: {}".format(self.entry_numtc.get()))
print ("Información Adicional: {}".format(self.entry_addinf.get()))
这篇关于类型错误:get() 需要 1 个位置参数,但给出了 3 个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!