Klick auf den Button der Wert wird um 1 erhöht
Verfasst: Samstag 30. Januar 2021, 13:12
Hallo, ich bin Python Anfängerin. Ich überlege wie ich es hinbekomme etwas immer wieder bei einem Klick auf einen Button ausführen kann. Es soll jedes Mal beim Klick auf den Button der Wert um 1 erhöht werden.
Code: Alles auswählen
import tkinter as tk
from tkinter import *
def einlesen():
print (eingabe.get())
def ausgabe():
print("Masche wurde hinzugefügt")
def aktionSF():
label = tk.Label(window, text="Masche wurde hinzugeügt", bg="yellow")
beginn=int(eingabefeld.get())
maschen=beginn+1
label=tk.Label(window,text=maschen)
label.pack()
window = tk.Tk()
window.geometry('400x200')
window.title("Maschenzähler")
label = tk.Label(window, fg="red")
label.pack(expand=1)
w = Label(window, text="Willkommen zum Maschenzaehler,\n bitte die Maschenzahl zu Beginn eingeben")
w.pack()
#bild1 = tk.PhotoImage(file="kuscheltiere.png")
#label2 = tk.Label(root, image=bild1).pack(side="right")
button=Button(window, text="+ 1 Masche", width=10, height=2, command=aktionSF)
button.pack(side='bottom')
button=Button(window,text='EXIT',width=10,height=2, command=window.destroy)
button.pack(side='bottom')
print ("Biite die Maschenzahl zu Beginn eingeben")
eingabefeld=Entry() #Erzeugt ein Eingabefenster
eingabefeld.pack()
window.mainloop()