首页 > 编程问答 >类型错误:下一个预计至少有 1 个参数,但得到 0

类型错误:下一个预计至少有 1 个参数,但得到 0

时间:2024-07-31 04:52:41浏览次数:9  
标签:python tkinter typeerror

在我一直在开发的应用程序中,我将其设置为具有三个窗口。当我单击第一页上的按钮打开一个新窗口时,它告诉我一个类型错误。我不明白,因为我将函数设置为“下一个” ' 没有任何争论。这是代码:

    from tkinter import*
    from ttkbootstrap.constants import*
    import ttkbootstrap as tb
    from PIL import Image,ImageTk

    first=tb.Window(themename="cosmo")
    first.geometry("1000x500+180+50")

   # Open an image file
    img = Image.open("C:/Intel/UAM.jpg")
    img_tk = ImageTk.PhotoImage(img)

  # Create a label and add the image to it
    first.columnconfigure(0,weight=10)
    first.columnconfigure(1,weight=1)

    pic= tb.Label(first, image=img_tk)
    pic.grid(row=0,column=0,rowspan=3,)

    first_btn=tb.Button(first, text="Next", command=next, bootstyle="primary",width=10)
    first_btn.grid(row=1,column=1,sticky=tb.W)



    def next():

    root=tb.Window(themename="cosmo")

    root.title("UAM Simple Evaluator")
    root.geometry("1000x500+180+50")
    root.lift()

    frame1=tb.Frame(root,bootstyle="light",borderwidth=0)
    frame1.pack(pady=18,padx=18)
    label1=tb.Label(frame1,text="Welcome to UAM Simple Evaluator!", font=("BrushScript", 24),bootstyle=("light,INVERSE"))
    label1.pack(pady=10,padx=10)

    paralabel2="""UAM Simple Evaluator utilizes the uniformly accelerated motion formulas 
    to return users with their desired physical quantities. In order to use it, 
    please input the numerical values of the known variables and 
    enter 'unknown' for the unknown variables below."""
    frame2=tb.Frame(root,bootstyle="light")
    frame2.pack(pady=5,padx=10)
    label2=tb.Label(frame2,text=paralabel2,font=("ComicSans",18),wraplength=900,borderwidth=0,bootstyle=('light,INVERSE'),justify='center')
    label2.pack(pady=10,padx=1,fill="both")
    global frame3
    frame3=tb.Frame(root,bootstyle='light')
    frame3.pack(pady=5,padx=10)               
    frame3.columnconfigure(0,weight=1)
    frame3.columnconfigure(1,weight=8)
    frame3.columnconfigure(4,weight=1)
    frame3.columnconfigure(5,weight=2)                           

    S=tb.StringVar(frame3)
    U=tb.StringVar(frame3)
    V=tb.StringVar(frame3)
    A=tb.StringVar(frame3)
    T=tb.StringVar(frame3)

    S_label=tb.Label(frame3, text="Displacement(m)", font=("Arial", 16))
    S_entry=tb.Entry(frame3, font=("Arial",16),textvariable=S)

    U_label=tb.Label(frame3, text="Initial Velocity(m/s)", font=("Arial", 16))
    U_entry=tb.Entry(frame3, font=("Arial",16),textvariable=U)
                 
    V_label=tb.Label(frame3, text="Final Velocity(m/s)", font=("Arial", 16))
    V_entry=tb.Entry(frame3, font=("Arial",16),textvariable=V)

    A_label=tb.Label(frame3, text="Acceleration(m/s^2)", font=("Arial", 16))
    A_entry=tb.Entry(frame3, font=("Arial",16),textvariable=A)
                 
    T_label=tb.Label(frame3, text="Time(s)", font=("Arial", 16))
    T_entry=tb.Entry(frame3, font=("Arial",16),textvariable=T)

    S_label.grid(row=0,column=0)
    S_entry.grid(row=0,column=1,sticky=tb.W)
    U_label.grid(row=1,column=0)                 
    U_entry.grid(row=1,column=1,sticky=tb.W)                
    V_label.grid(row=2,column=0)
    V_entry.grid(row=2,column=1,sticky=tb.W)
    A_label.grid(row=3,column=0)
    A_entry.grid(row=3,column=1,sticky=tb.W)
    T_label.grid(row=4,column=0)
    T_entry.grid(row=4,column=1,sticky=tb.W)
 

    def UAM_Eval():
     global S
     global U
     global V
     global A
     global T
     if S.get()=='unknown' and A.get()=='unknown':
      S1=((float(U.get())+float(V.get()))*float(T.get()))/2
      A1=(float(V.get())-float(U.get()))/float(T.get())
      S2=round(S1,2)
      A2=round(A1,2)
      print("The value of the distance is",(S2))
      print("The value of the acceleration is",(A2))
    elif S.get()=='unknown' and V.get()=='unknown':
      S3=(float(U.get())*float(T.get()))+((float(A.get())*(float(T.get())**2))/2)
      V1=float(U.get())+(float(A.get())*float(T.get()))
      S4=round(S3,2)
      V2=round(V1,2)
      print("The value of the distance is",S4)
      print("The value of the final velocity is",V2)
    elif S.get()=='unknown' and U.get()=='unknown':
      S5=(float(V.get())*float(T.get()))-(float(A.get())*(float(T.get())**2))/2
      U1='float(V.get())-(float(A.get())*float(T.get()))'
      S6=round(S5,2)
      U2=round(U1,2)
      print("The value of the distance is",S6)
      print("The value of the initial velocity is",U2)
    elif S.get()=='unknown' and T.get()=='unknown':
      S7=((float(V.get())**2)-(float(U.get())**2))/(2*float(A.get()))
      T1=(float(V.get())-float(U.get()))/float(A.get())
      S8=round(S7,2)
      T2=round(T1,2)
      print("The value of the distance is",S8)
      print("The value of the time is",T2)
    elif U.get()=='unknown' and A.get()=='unknown':
      U3=((2*float(S.get()))/float(T.get()))-float(V.get())
      A3=(-2*(float(S.get())-(float(V.get())*float(T.get()))))/(float(T.get())**2)
      U4=round(U2,2)
      A4=round(A2,2)
      print("The value of the initial velocity is",(U4))
      print("The value of the acceleration is",(A4))
    elif U.get()=='unknown' and V.get()=='unknown':
      U5=(float(S.get())-((float(A.get())*(float(T.get())**2))/2))/float(T.get())
      V3=(float(S.get())+((float(A.get())*(float(T.get())**2))/2))/float(T.get())
      U6=round(U5,2)
      V4=round(V3,2)
      print("The value of the initial velocity is",U6)
      print("The value of the final velocity is",V4)
    elif U.get()=='unknown' and T.get()=='unknown':
     U7=((float(V.get())**2)-(2*(float(A.get())*float(S.get()))))**(1/2)
     U8=round(U7,2)
     T3=(float(V.get())-float(U7))/float(A.get())
     T4=round(T3,2)
     print("The value of the initial velocity is",U8)
     print("The value of the time is",T4)
    elif V.get()=='unknown' and A.get()=='unknown':
     V5=((2*float(S.get()))/float(T.get()))-float(U.get())
     A5=((2*(float(S.get())-(float(U.get())*float(T.get())))))/(float(T.get())**2)
     V6=round(V5,2)
     A6=round(A5,2)
     print("The value of the final velocity is",V6)
     print("The value of the acceleration is",A6)
    elif V.get()=='unknown' and T.get()=='unknown':
     V7=((float(U.get())**2)+(2*float(A.get())*float(S.get())))**(1/2)
     V8=round(V7,2)
     T5=(float(V7)-float(U.get()))/float(A.get())
     T6=round(eval(T5),2)
     print("The value of the final velocity is",V8)
     print("The value of the time is",T6)
    elif A.get()=='unknown' and T.get()=='unknown':
     A7=((float(V.get())**2)-(float(U.get())**2))/(2*float(S.get()))
     T7=(2*float(S.get()))/(float(U.get())+float(V.get()))
     A8=round(A7,2)
     T8=round(T7,2)
     print("The value of the acceleration is",A8)
     print("The value of the time is",T8)
    
    def result_printer():
     results_window=tb.Window()
     results_window.geometry("1000x500+180+50")
   
    global result_label
    result=UAM_Eval()
    result_label.config(text=result)
    
    result_frame=tb.Frame(results_window,bootstyle="light")
    result_frame.pack(padx=15,pady=50)
    result_label=tb.Label(result_frame,text="Here is the answer",font=("Arial",18))
    result_label.pack(pady=50,padx=10)
    results_window.mainloop()
    
 
    Calc_btn=tb.Button(frame3, text="Calculate", command=UAM_Eval, width=20,bootstyle="primary")
    result_btn=tb.Button(frame3,text="Next Page",command=result_printer,width=20,bootstyle="info")
    result_label=tb.Label(root,text="Result will be shown here.")
    result_label.pack(padx=10,pady=50)
    Calc_btn.grid(row=5,column=1,rowspan=2,sticky=tb.N)
    result_btn.grid(row=8,column=1,)
    root.mainloop()
    first.mainloop()

我缺少什么? 我希望得到一些帮助。


这个错误信息表明你在调用函数 next 的时候没有使用括号。在 Python 中,调用函数需要在函数名后面加上括号,即使函数不需要任何参数。

command=next 改为 command=next() 就可以解决这个问题。

以下是修改后的代码:

first_btn=tb.Button(first, text="Next", command=next(), bootstyle="primary",width=10)
first_btn.grid(row=1,column=1,sticky=tb.W)

另外,你的代码中还存在一些其他的问题:

  1. next() 函数被定义在 first.mainloop() 之后,这会导致函数无法被调用。 你应该将 next() 函数的定义移到 first_btn 的定义之前。

  2. result_printer 函数中,你调用了 UAM_Eval 函数,但是没有将返回值赋给变量 result 你应该将 result = UAM_Eval()

  3. UAM_Eval 函数中,你使用了大量的 if-elif 语句,这使得代码难以阅读和维护。 你可以考虑使用字典或者其他数据结构来简化代码。

  4. 你在 UAM_Eval 函数中使用了全局变量,这是一种不好的编程习惯。 你可以考虑将这些变量作为参数传递给函数。

建议你仔细检查代码,并根据以上建议进行修改。

标签:python,tkinter,typeerror
From: 78813072

相关文章

  • python函数:带星号的参数一个接一个
    我想知道为什么定义以下函数被认为是好的。deffoo(*x,y):pass据我所知,现在有调用此函数的方法,因为它总是缺少y的值。(如果我错了,请纠正我。)这有什么我不知道的用处吗?你说得对,在Python中定义一个像deffoo(*x,y):...这样的函数,在试图以常规方......
  • 基于遗传(GA)、粒子群(PSO)、模拟退火(SA)、禁忌搜索(ST)、蚁群算法(ACO)、自自组织神
        ......
  • 10个append()函数在Python程序开发中的创新应用
    文末赠免费精品编程资料~~在Python编程的世界里,append()函数是列表操作中最常见的方法之一。它允许我们在列表的末尾添加一个元素,这一简单的功能却能激发无限的创造力。今天,我们将探讨append()函数在Python程序开发中的10种创新应用,从基本用法到高级技巧,逐步深入。1.构......
  • 全网最适合入门的面向对象编程教程:28 类和对象的Python实现-Python编程原则、哲学和规
    全网最适合入门的面向对象编程教程:28类和对象的Python实现-Python编程原则、哲学和规范大汇总摘要:本文主要介绍了在使用Python进行面向对象编程时,Python异常处理的原则-“请求谅解,而非许可”,以及软件设计和Python的编程原则,同时介绍了PEP8规范。原文链接:FreakStud......
  • python生成器
    一前言环境:python3.10win10二生成器1关于生成器先看一个例子    定义了一个函数,当我们运行该函数时,并未像普通函数那样执行函数体内的代码    从其中的英文可知,执行函数得到了一个生成器对象,这个生成器对象也叫做generatoriterator(生成器迭代器),generatorit......
  • 生成MySQL-oracle-SQL server数据字典(附Python代码)
    生成数据字典,早年写的,请注意新的版本变化。(1)MySQL元数据SQLUSEinformation_schema;#取出库和表。select  TABLE_SCHEMAAS'数据库名称',  TABLE_NAMEAS'表名',  TABLE_TYPEAS'表类型',  ROW_FORMATAS'行格式',  ENGINEAS'数据库引擎',  TABL......
  • Python - Method Resolution Order (MRO)
    TheorderinwhichPythonsearchesforattributesinbaseclassesiscalledmethodresolutionorder(MRO).Itgivesalinearizedpathforaninheritancestructure.PythoncomputesanMROforeveryclassinthehierarchy;thisMROiscomputedusingthe‘C3......
  • 计算机毕业设计选题推荐-零食批发商仓库管理系统-Java/Python项目实战
    ✨作者主页:IT研究室✨个人简介:曾从事计算机专业培训教学,擅长Java、Python、微信小程序、Golang、安卓Android等项目实战。接项目定制开发、代码讲解、答辩教学、文档编写、降重等。☑文末获取源码☑精彩专栏推荐⬇⬇⬇Java项目Python项目安卓项目微信小程序项目......
  • 【自动化测试必学语言】python:语言基础
    目录Python介绍语言的分类注释单行注释多行注释变量定义变量使用变量变量名的命名规范数据类型数字类型非数字类型type()函数input输入print输出格式化输出快捷键(小操作)运算符算术运算符 比较运算符Python介绍作者:吉多·范罗苏姆(Guidov......
  • 【已解决】TypeError: argument of type ‘int’ is not iterable
    【已解决】TypeError:argumentoftype‘int’isnotiterable在Python编程中,TypeError:argumentoftype'int'isnotiterable是一个常见的错误。此错误表明你尝试对一个整数(int)执行迭代操作,但整数是不可迭代的。本文将深入探讨此错误的根源、解决思路、具体解......