get'typeError:insertstop()采用0个位置参数,但给出了1个。当我的函数调用中没有参数时

发布于 2025-01-27 09:22:29 字数 2450 浏览 3 评论 0原文

我是Python的新手,我正在尝试将我的第一个应用程序放在一起,将旅行信息插入并将其插入文本框中以导出到文档中。直到今天,当我尝试实现多种方式将文本从入口箱中插入文本块中的多种方式,它的发展都非常好。

我有一个输入小部件,可以在按下按钮时将文本插入文本小部件。这很简单,但我想让它进入可以直接点击Enter键做同样的事情的地方。

当我实现此功能时,我会收到错误:

“ tkinter回调中的异常 Trackback(最近的最新电话): 文件“ C:\ Program Files \ Spyder \ PKGS \ tkinter_ init _。py”,第1892行,在__呼叫__ 返回self.func(*args) TypeError: insertstop() takes 0 positional arguments but 1 was given"

I've looked the error up and it seems like it would pop up if I put in arguments in my function call but I don't have any arguments in any of my function calls. Also it seems like maybe this error is related to a class or something? I haven't learned about classes yet and only have a basic idea of what they are. Do I need a class to do this?

Coincidentally I also added the argument(self) in my function and that made pressing enter work but it made my insert stop button quit working.

I'm sure I've missed something very basic but I just can't figure out what.

Thanks for any help!

import time
import os
import sys
from tkinter import *

# Creates the Tkinter form named "screen"
screen = Tk()
screen.geometry("550x645")
screen.title("Test")
# Initialize frames
menuframe = Frame(screen,
                  height=60,width=600,bg="gray",pady=5)
inputframe = Frame(screen,
                   height=300,width=600,pady=5)
outputframe = Frame(screen,
                   height=290,width=600,pady=5)

# Packs the frames so they will display
menuframe.pack()
inputframe.pack()
outputframe.pack()


#==STOPBOX==#

stopbox=Text(inputframe,yscrollcommand=1,height= 10,width=20,
               padx=3,pady=3,relief=GROOVE,bg="gray79")
stopbox.place(x=345, y=90)

def insertstop():
    global stop_vanconv
    stop_vanconv=(stop_entry.get())
    stopbox.insert(END, stop_vanconv + "\n")
    stop_entry.delete("0","end")
    

stoplist_label = Label(inputframe,
                       text="Type stop locations and press" + '\n' +
                       "the Add Stop button to insert a new stop.")
stoplist_label.place(x=100, y=150)

stop_entry = Entry(inputframe,
                      textvariable = " ")
stop_entry.place(x=150, y=190)

addstopbutton = Button(inputframe,text="Add Stop",padx=20,pady=0,
                       activebackground="darkslategray4",command=insertstop)
addstopbutton.place(x=160, y=220)

stop_entry.bind('<Return>',insertstop)

screen.mainloop()

I'm very new to Python and I'm trying to put my first application together that takes in trip information and inserts it into a text box for export out to a document. It's gone pretty good until today when I tried to implement multiple ways of inserting text from an entrybox into a text block with tkinter.

I have an entry widget that inserts text into a text widget when a button is pressed. That's simple enough but I wanted to make it to where you could simply hit the enter key to do the same thing.

When I implement this function I get the error:

"Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\Spyder\pkgs\tkinter_init_.py", line 1892, in __ call __
return self.func(*args)
TypeError: insertstop() takes 0 positional arguments but 1 was given"

I've looked the error up and it seems like it would pop up if I put in arguments in my function call but I don't have any arguments in any of my function calls. Also it seems like maybe this error is related to a class or something? I haven't learned about classes yet and only have a basic idea of what they are. Do I need a class to do this?

Coincidentally I also added the argument(self) in my function and that made pressing enter work but it made my insert stop button quit working.

I'm sure I've missed something very basic but I just can't figure out what.

Thanks for any help!

import time
import os
import sys
from tkinter import *

# Creates the Tkinter form named "screen"
screen = Tk()
screen.geometry("550x645")
screen.title("Test")
# Initialize frames
menuframe = Frame(screen,
                  height=60,width=600,bg="gray",pady=5)
inputframe = Frame(screen,
                   height=300,width=600,pady=5)
outputframe = Frame(screen,
                   height=290,width=600,pady=5)

# Packs the frames so they will display
menuframe.pack()
inputframe.pack()
outputframe.pack()


#==STOPBOX==#

stopbox=Text(inputframe,yscrollcommand=1,height= 10,width=20,
               padx=3,pady=3,relief=GROOVE,bg="gray79")
stopbox.place(x=345, y=90)

def insertstop():
    global stop_vanconv
    stop_vanconv=(stop_entry.get())
    stopbox.insert(END, stop_vanconv + "\n")
    stop_entry.delete("0","end")
    

stoplist_label = Label(inputframe,
                       text="Type stop locations and press" + '\n' +
                       "the Add Stop button to insert a new stop.")
stoplist_label.place(x=100, y=150)

stop_entry = Entry(inputframe,
                      textvariable = " ")
stop_entry.place(x=150, y=190)

addstopbutton = Button(inputframe,text="Add Stop",padx=20,pady=0,
                       activebackground="darkslategray4",command=insertstop)
addstopbutton.place(x=160, y=220)

stop_entry.bind('<Return>',insertstop)

screen.mainloop()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文