简体   繁体   English

如何修复 Python 中的“TypeError: MOVE() 需要 0 个位置参数,但给出了 1 个”

[英]How to fix 'TypeError: MOVE() takes 0 positional arguments but 1 was given' in Python

Trying to make a simple drawing program based on x an y coordinates an i'm using a function to draw and modify the coordinates in one call without actually giving valuea to the function itself using global variables for what needs modification by the function but it still seees as if i've given it actual direct input.尝试基于 x 和 y 坐标制作一个简单的绘图程序,我正在使用一个函数在一次调用中绘制和修改坐标,而没有实际使用全局变量为函数本身赋予 valuea 以供函数修改,但它仍然看起来好像我已经给了它实际的直接输入。

In a previous version i got away by using a class to memorize the ghanging coordinates and functions of the respective class to do the drawing, but in this case the input method is slightly different since i'm using the scale widget isntead of the buttons and as i mentioned before i did try using global variables in both programs actually and it doesn't work in either of them.在以前的版本中,我通过使用一个类来记住各个类的悬挂坐标和函数来进行绘图,但在这种情况下,输入方法略有不同,因为我使用的是按钮的缩放小部件而不是按钮和正如我之前提到的,我确实尝试在两个程序中使用全局变量,但在其中任何一个程序中都不起作用。

from tkinter import *

win=Tk()
win.title("Etch a Schetch")
win.configure(background="grey")
win.configure(bd=5)

global xa
xa=0
global ya
ya=0

def MOVE():
    tabla.create_line(xa,ya,sx.get(),sy.get())
    xa=sx.get()
    ya=sy.get()


tabla=Canvas(win,width=300,height=300)


sx=Scale(win,from_=0,to=300,length=300,orient="horizontal",command=MOVE)

sy=Scale(win,from_=0,to=300,length=300,command=MOVE)

ex=Button(win,text="Exit",command=exit)


tabla.grid(row=1,column=1)
sx.grid(row=2,column=1)
sy.grid(row=1,column=2)
ex.grid(row=2,column=2)

win.mainloop()

If it would work it would be kinda like an etch a sketch.如果它可以工作,它会有点像蚀刻草图。

I actually just realized what the problem was, to quote mkiever who commented first but i didn't understand untill i did some individuall testing on the interaction between "Scale" and the command that is calling.我实际上刚刚意识到问题是什么,引用首先发表评论的 mkiever 但我不明白,直到我对“Scale”和正在调用的命令之间的交互进行了一些单独的测试。 To put it short and easier to understand the function that is beeing called by "Scale" as its command automaticly takes the value of the scale as an input to the function, as a rezult i only need one declared variable in the paranthesis when i define the function but no paranthesis or input variable is required to give an input to it from the scale.简而言之,更容易理解被“Scale”调用的函数,因为它的命令会自动将刻度的值作为函数的输入,作为一个结果,当我定义时,我只需要在括号中声明一个变量函数,但不需要括号或输入变量来从尺度向它提供输入。

EXAMPLE:例子:

from tkinter import *
import time

win=Tk()

def P(a):
    print(a)

sx=Scale(win,from_=0,to=300,length=300,orient="horizontal",command=P)
sx.pack()

win.mainloop()

Some alteration to the code is still required but it'll be much easier without that pesky error showing up.仍然需要对代码进行一些修改,但是如果不出现那个讨厌的错误,它会容易得多。

Thank you everyone for your advice.谢谢大家的建议。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何解决“ TypeError:main()接受0个位置参数,但给出了1个”? - how to fix “TypeError: main() takes 0 positional arguments but 1 was given”? Python:TypeError:draw()接受0个位置参数,但给出了1个 - Python: TypeError: draw() takes 0 positional arguments but 1 was given Python TypeError:接受 4 个位置参数,但给出了 5 个 - Python TypeError: takes 4 positional arguments but 5 were given TypeError:取 0 位置 arguments 但给出 1 - TypeError: takes 0 positional arguments but 1 was given 如何修复分数 function 以使其与 GridsearchCV 一起使用,TypeError: score() 需要 2 个位置 arguments 但给出了 3 个 - How to fix Score function for it to work with GridsearchCV, TypeError: score() takes 2 positional arguments but 3 were given 拟合曲线时如何解决“ TypeError:当给定4个错误时,f()接受3个位置参数” - How to fix “TypeError: f() takes 3 positional arguments when 4 were given error” when fitting a curve 如何解决“ TypeError:fit_transform()需要2个位置参数,但给出了3个” - How to fix “TypeError: fit_transform() takes 2 positional arguments but 3 were given” Python TypeError:衍生物_circ()接受2个位置参数,但给出了6个 - Python TypeError: derivatives_circ() takes 2 positional arguments but 6 were given TypeError:__init __()接受2个位置参数,但是给了3个Python 3? - TypeError: __init__() takes 2 positional arguments but 3 were given Python 3? Python:TypeError: <lambda> ()接受0个位置参数,但由于断言而给出了1个 - Python: TypeError: <lambda>() takes 0 positional arguments but 1 was given due to assert
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM