Ich hab 2 Buttons, einen zum Hochzählen und einen zum Runterzählen(jeweils um 1) und das Ausgabelabel.
Die Darstellung funktioniert auch so wie sie soll, nur wird keine funktion ausgeführt, das Label bleibt bei 0 stehen.
Code: Alles auswählen
import tkinter as tk
class Application(tk.Frame):
def __init__(self,master=None):
tk.Frame.__init__(self,master)
self.pack()
self.createWidgets()
def createWidgets(self):
self.b1=tk.Button(text="Count +",command=Zahlenwert1.count_mehr())
self.b2=tk.Button(text="Count -",command=Zahlenwert1.count_weniger())
self.b3=tk.Button(text="Ende",command=root.destroy)
self.l1=tk.Label(text=Zahlenwert1.Ausgabe())
self.b1.pack()
self.l1.pack()
self.b2.pack()
self.b3.pack()
class counter:
def __init__(self,z):
self.Anzahl=z
def count_mehr(self):
self.Anzahl+=1
print(self.Anzahl)
def count_weniger(self):
self.Anzahl-=1
print(self.Anzahl)
def Ausgabe(self):
print (self.Anzahl)
return self.Anzahl
Zahlenwert1=counter(0)
root=tk.Tk()
app=Application(master=root)
app.mainloop()
Warum tut sich da nix?