Home > Software design >  tkinter input text box return value error
tkinter input text box return value error

Time:09-14

I am trying to utilize 3 inputs to print the value "True". Voltage_Variable and Phase_Variable both are dropdown boxes while Power_Varialbe is an inputed value.

If i run the code without the Power_Variable ie. removing it from my created "function", then the code works fine

This is the error I am recieving with the Power_Variable input box: TypeError: Retrieve..() missing 1 required positional argument: 'x'

it is not recognizing my inputed Power Value so it is saying the input is missing, therefore not allowing my function to run

Can someone tell what I am missing?

Here is the code:

from tkinter import *

def Retrieve():
    Window = Tk()
    Window.title("EH")
    Window.geometry("500x400")

    Power_Variable = StringVar(Window)
    Power_Select_Text_Box = Text(Window, height=1, width=8)
    Power_Select_Text_Box.grid(row=0, column=0)
    Power_Select=Button(Window, height=1, width=15, text="Power (KW) Select", command=lambda 
    x: function(x, Voltage_Variable.get(), Phase_Variable.get(), Window))
    Power_Select.grid(row=1, column=0 )


    Voltage_Variable = StringVar(Window)
    Voltage_Variable.set("VOLTAGE")
    Voltage = ["120", "208", "240", "277", "480"]
    Voltage_Dropdown = OptionMenu(Window, Voltage_Variable, *Voltage, command=lambda x:  
    function(Power_Variable.get(), x, Phase_Variable.get(), Window))
    Voltage_Dropdown.grid(row=0, column=1)


    Phase_Variable = StringVar(Window)
    Phase_Variable.set("PHASE")
    Phase = ["SINGLE PHASE", "THREE PHASE"]
    Phase_Dropdown = OptionMenu(Window, Phase_Variable, *Phase, command=lambda x: 
    function(Power_Variable.get(), Voltage_Variable.get(), x, Window))
    Phase_Dropdown.grid(row=0, column=2)


    Window.mainloop()


def function (Power, Voltage, Phase, Window):
    if Power == "10" and Voltage == "120" and Phase == "SINGLE PHASE":
        print (True)                           


Retrieve()

CodePudding user response:

Here is the complete code section for Power_Variable.

Text widget is replaced by Entry widget and Power_select command is changed so that all parameters are passed to function.

    Power_Variable = StringVar(0)
    Power_Select_Text_Box = Entry(Window, width=8, textvariable = Power_Variable)
    Power_Select_Text_Box.grid(row=0, column=0)
    Power_Select=Button(
        Window, height=1, width=15, text="Power (KW) Select",
        command=lambda: function(Power_Variable.get(), Voltage_Variable.get(), Phase_Variable.get(), Window))
    Power_Select.grid(row=1, column=0 )
  • Related