0
Three_Series = ["3S BLACK STOCK RIMS.png"]

def SelectedCarFunction(event=None):
    Model = Var2.get()
    Colour = Var3.get()
    Wheels = Var4.get()

The variables Model, Colour and Wheels are retrieved perfectly as they should be

if Model == "3 Series" and Colour == "Black" and Wheels == "Stock":
    VarSC = Three_Series[0]
    print(VarSC)

I put print(VarSC) here to test to see if it would print "3S BLACK STOCK RIMS.png" and it did

   return VarSC

VarSC = StringVar()

DisplayFrame.grid_propagate(False)

print(VarSC)

However, now when I print(VarSC) to see if it prints the same value as be before it doesn't, instead it prints out PY_VAR9

CarImage = PhotoImage(file=VarSC)

Here I want to assign the file to VarSC, i.e I want VarSC to equal "3S BLACK STOCK RIMS.png" but it doesn't

CarImageLabel = Label(DisplayFrame, image=CarImage)
CarImageLabel.grid(row=0, column=0)

root.mainloop()

Here's the entire code:

Three_Series = ["3S BLACK STOCK RIMS.png"]

def SelectedCarFunction(event=None):
    Model = Var2.get()
    Colour = Var3.get()
    Wheels = Var4.get()

    if Model == "3 Series" and Colour == "Black" and Wheels == "Stock":
    VarSC = Three_Series[0]
    print(VarSC)
    return VarSC

VarSC = StringVar()

DisplayFrame.grid_propagate(False)

print(VarSC)
CarImage = PhotoImage(file=VarSC)
CarImageLabel = Label(DisplayFrame, image=CarImage)
CarImageLabel.grid(row=0, column=0)

root.mainloop()
Nissa
  • 4,636
  • 8
  • 29
  • 37
  • Please post the entire code in a single block. It is impossible to see what is actually happening. – Brian Pendleton Oct 23 '16 at 12:20
  • Done, posted the entire code underneath @BrianPendleton – Usman Jameel Oct 23 '16 at 12:35
  • If you want `VarSC` to be the result of `SelectedCarFunction`, then you need to say `VarSc = SelectedCarFunction()`? I'm still confused because you have a lot of missing context and code still. What is `root`? – Brian Pendleton Oct 23 '16 at 12:40
  • Root is used as this is GUI program on tkinter. The value of VarSC in the function is "3S BLACK STOCK RIMS.png" but when I try to use VarSC outside the function it gives me PY_VAR9. How can I get the same value of VarSC outside the function?? @BrianPendleton – Usman Jameel Oct 23 '16 at 12:53
  • I'd have a look at other answer for updating global variables inside functions. http://stackoverflow.com/a/17307521/4080476 – Brian Pendleton Oct 23 '16 at 12:57
  • I had a look and tried using global VarSC in the function but that did not solve the problem @BrianPendleton – Usman Jameel Oct 23 '16 at 13:01
  • @Brian Oakley HELP?!? – Usman Jameel Oct 23 '16 at 13:56
  • Nothing in the code you've shown ever calls your `SelectedCarFunction`, so its return value cannot possibly be used anywhere. If it's being called from somewhere you haven't shown, well, we can't debug code we can't see. Please show enough of your code that we can actually run it and see the same problem you're describing. – Blckknght Oct 24 '16 at 01:47

0 Answers0