Hallo,
ich habe das Problem dass ich einen int() in einem label integrieren möchte bietet tkinter dazu eine Lösung
Momentan:
Richtige = int()
tkinter.Label(root, textvariable = Richtige)
allerdings habe ich ja einen int und keine var.
Bitte um Antwort bzw. Lösung
Int in Lable anzeigen
Hi Tom12
Was hälst du hiervon:Gruss wuf
Was hälst du hiervon:
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: utf-8 -*-
try:
#~~ For Python 2.x
import Tkinter as tk
except ImportError:
#~~ For Python 3.x
import tkinter as tk
app_win = tk.Tk()
my_int_var = tk.IntVar()
tk.Label(app_win, textvariable=my_int_var). pack(padx=10, pady=10)
my_int_var.set(1000)
print("Type:{}, Value:{}".format(type(my_int_var.get()), my_int_var.get()))
app_win.mainloop()
Take it easy Mates!
Hallo wuf,
Danke, kannte den Befehl IntVar() noch nicht funktioniert.
Allerdings möchte ich, dass wenn ein Button geklickt wird dem Int eins dazugezählt wird.
normalerweise würde es ja
Richtige + 1
sein allerdings bekomme ich den error:
unsupportet operand type(s) for +: "IntVar" and "int"
Danke, kannte den Befehl IntVar() noch nicht funktioniert.
Allerdings möchte ich, dass wenn ein Button geklickt wird dem Int eins dazugezählt wird.
normalerweise würde es ja
Richtige + 1
sein allerdings bekomme ich den error:
unsupportet operand type(s) for +: "IntVar" and "int"
Hi Tom12
Kein Problem:Gruss wuf
Kein Problem:
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: utf-8 -*-
try:
#~~ For Python 2.x
import Tkinter as tk
except ImportError:
#~~ For Python 3.x
import tkinter as tk
app_win = tk.Tk()
my_int_var = tk.IntVar()
tk.Label(app_win, textvariable=my_int_var, font=16). pack(padx=10, pady=10)
my_int_var.set(1000)
tk.Button(app_win, text="Addiere 1",
command=lambda: my_int_var.set(my_int_var.get()+1)).pack(padx=10, pady=10)
app_win.mainloop()
Take it easy Mates!