TypeError:phrase_display()缺少1个必需的位置参数:"x" [英] TypeError: phrase_display() missing 1 required positional argument: 'x'

查看:146
本文介绍了TypeError:phrase_display()缺少1个必需的位置参数:"x"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不断收到此错误.有人知道如何解决这个问题吗?

I keep getting this error. Does anyone know how to solve this?

from tkinter import *
import random
import tkinter as tk
import pandas as pd
from Datamine import *


#create window
window = tk.Tk()
window.title("JCET Search System")
window.geometry("500x500")


def datamine():
# read excel files
    df = pd.read_excel ('N:/TEST/TEST UTILIZATION/IA 2020/Dev/SCS-FT-IE-Report.xlsm', sheet_name= 'FT')
    df2 = pd.read_excel ('N:/TEST/TEST UTILIZATION/IA 2020/Dev/HW_STATUS_TOTAL_FEB28.xlsx', sheet_name= 'HW_STATUS_TOTAL_FEB28')
    df1 = pd.DataFrame(df, columns = ["MFG Device", "LOADBOARDGRPNAME","SOCKETGRPNAME", "PRIHANDLERFULLKIT"])
    df1.set_index("MFG Device")
    i=0
#store user input into value
    greeting = entrymc.get()
#search results containing value
    x = df1[df1['MFG Device'].str.contains(greeting)]
#display search results (in shell)
    print(x)
    return(x) 

#function for command
#def callback2():
   # name = "You entered: ",entrymc.get()
    
    #return name 

#display text
def phrase_display(x):
    
    textbox1.delete("1.0", "end")
    textbox1.insert(tk.END, str(x))
    textbox1.pack()
    
    
# to have more than 2 commands in a button    
def combine_funcs(*funcs):
    def combined_func(*args, **kwargs):
        for f in funcs:
            f(*args, **kwargs)
    return combined_func

#label
labelmc = tk.Label(text="Enter Parts ID #", fg= "black")
labelmc.grid(column=1, row=2)

label5 = tk.Label(text="Results", fg= "black")
label5.grid(column=1, row=7)

#entry field
entrymc = tk.Entry(width = 30)
entrymc.grid(column=2, row=2)

#button
button1 = tk.Button(text="Submit", command= combine_funcs(datamine, phrase_display))
button1.grid(column=4, row=2)

#text box
textbox1 = tk.Text(master=window, height=15, width =50, bg="white")
textbox1.grid(column=1,row=10, columnspan=7, rowspan =500)


window.mainloop()

外壳: Tkinter回调中的异常 追溯(最近一次通话): 在调用中的文件"C:\ Users \ sgtiocqn \ AppData \ Local \ Programs \ Thonny \ lib \ tkinter_ init _.py"中,行1705 返回self.func(* args) 文件"C:\ Users \ sgtiocqn \ Desktop \ gui.py",第47行,combined_func f(* args,** kwargs) TypeError:phrase_display()缺少1个必需的位置参数:'x'

Shell: Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\sgtiocqn\AppData\Local\Programs\Thonny\lib\tkinter_init_.py", line 1705, in call return self.func(*args) File "C:\Users\sgtiocqn\Desktop\gui.py", line 47, in combined_func f(*args, **kwargs) TypeError: phrase_display() missing 1 required positional argument: 'x'

推荐答案

在您的代码中,phrase_display()需要一个x参数.

In your code, phrase_display() requires an x parameter.

   def phrase_display(x):
       textbox1.delete("1.0", "end")
       textbox1.insert(tk.END, str(x))
       textbox1.pack()

但是在Combined_funcs()

But in combined_funcs()

# to have more than 2 commands in a button    
def combine_funcs(*funcs):
    def combined_func(*args, **kwargs):
        for f in funcs:
            f(*args, **kwargs)
    return combined_func

您正在同时调用datamine()和phrase_display().虽然datamine()不需要参数,但是phrase_display()却需要;但是您没有在调用中提供x参数. f(*args, **kwargs).

You are calling both datamine() and phrase_display(). While datamine() doesn't need a parameter, phrase_display() does; but you aren't supplying the x parameter in the call. f(*args, **kwargs).

我认为[1]或[2]是您可以看的东西.

I think [1] or [2] are something you can look at.

[1]-如何将参数传递给Tkinter中有一个Button命令?

[2]- 查看全文

相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆