Eli Kerrison-Male Eli Kerrison-Male - 1 year ago 54
Python Question

How to make IntVar and StringVar display in the same widget?

So, I am trying make a label that displays both StringVar and an IntVar, though when I try to put them in, like so...

from tkinter import *
from tkinter import ttk

root = Tk()
parent = ttk.Frame(root)

string = StringVar()
integer = IntVar()

string.set("Blah =")

both = str((string.get(), str(integer.get())))

both = StringVar()
both.set((string.get(), str(integer.get())))

label = ttk.Label(parent, textvariable=(both))


Now, this is the closest I was able to get, because the other ways didn't even display the textvariables in the widget.
For some reason the code when printed returns: ('Blah =', '10').

Like a list that has been printed. But the label displays: {Blah =} 10

Can someone please tell me why it displays with these instead of just displaying the variables.

Answer Source

I think you are looking for how to format a string.

both = StringVar()
both.set( "{}{}".format( string.get(), integer.get() ) )