Python Forum
[Tkinter] Updating box with Drop Down selection
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Updating box with Drop Down selection
#1
Hi all,

I am fairly new to using Tkinter and ive created a drop down list but what i want to do if a user selects a destination for the text box to display calculations from weight outputs * by the destination weight.

The entry fields are what the weight the user is taking i want to display the DisplayAv (output) * the weight of the travelling destination.
def Weight():
    # Convert Crew Weight of 100KG
    Entry1 = float(entName1.get())-CrewAllowance
    Entry2 = float(entName2.get())-CrewAllowance
    Entry3 = float(entName3.get())-CrewAllowance
    Entry4 = float(entName4.get())-CrewAllowance

    # Mission Crew Weight of 150KG

    Entry5 = float(entName5.get())-MissionAllowance
    Entry6 = float(entName6.get())-MissionAllowance

    # Enters converted weight to
    # the text widget

    DisplayAv1.delete("1.0", END)
    DisplayAv1.insert(END, Entry1)
    DisplayAv2.delete("1.0", END)
    DisplayAv2.insert(END, Entry2)
    DisplayAv3.delete("1.0", END)
    DisplayAv3.insert(END, Entry3)
    DisplayAv4.delete("1.0", END)
    DisplayAv4.insert(END, Entry4)
    DisplayAv5.delete("1.0", END)
    DisplayAv5.insert(END, Entry5)
    DisplayAv6.delete("1.0", END)
    DisplayAv6.insert(END, Entry6)
    
    Drop = DropBox.get()
    Display1.delete("1.0", END)
    Display1.insert(END, DropVal)

def DropVal(DropBox):
    if Drop==options[0]:
        Display1 = "0.378"
        Display1.set

# List of options:

options=[
    "Please Select a Destination",
    "Destination1",
    "Destination2",
    "Destination3",
    "Destination4",
    "Destination5",
    "Destination6",
    "Destination7",
    "Destination8"
    ]
    
DropBox = StringVar()
DropBox.set("Please Select a Destination")

# Drop down box for MASS

Dropdown = OptionMenu(main, DropBox, *options,)
Dropdown.grid(row=8, column=5)
Hope this makes sense on what i am trying to do, thanks everyone

Hi All,

The box i am trying to get to update with the calculations displays the below in the text box.

* <function DropVal at 0x1030c73a0> *

Haven't been able to figure out why this is happening
Reply
#2
Could you provide all the code please?
Reply
#3
The line
Display1.insert(END, DropVal)
passes a reference to DropVal as it is not called with ()

If the function DropVal was called, it does not return anything so None would be returned.
Reply
#4
(May-12-2020, 04:04 PM)Yoriz Wrote: The line
Display1.insert(END, DropVal)
passes a reference to DropVal as it is not called with ()

If the function DropVal was called, it does not return anything so None would be returned.

Thanks heaps for your comment

I have changed the if statement to be:

if Drop==options[1]:
        weightlist = [0]
        Display1.set(weightlist[0]) 

# Lists

options=[
    "Please Select a Destination",
    "Destinationone",
    "Destinationtwo",
    "Destinationthree",
    "Destinationfour",
    "Destinationfive",
    "Destinationsix",
    "Destiinationseven",
    "Destinationeight"
    ]

weightlist=[
    0.3,
    0.9,
    0.16,
    0.3,
    0.18,
    0.13,
    0.14,
    0.12,
    ]
I am trying to work out if a user selects 'Destinationone' how to display the number in weightlist 0.3.

Would you have any ideas on how i can do this?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Kivy] Create a function to store text fields and drop downs selection in KivyMD floxia 0 1,650 Dec-18-2022, 04:34 AM
Last Post: floxia

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020