Ich bin neu hier... und auch neu in der Programmierung! Habe aber den Spass daran entdeckt und "spiele" seit ein paar Tagen mit Python rum.
Nun hänge ich super Anfänger bei einem Problem seit 2 Tagen fest. Ich habe ein kleines Beispiel Programm geschrieben (inhaltlich macht es keinen grossen Sinn).
Da habe ich eine Schieberegler eingebaut. Mit einem Submit Button. Beim drücken des Buttons soll das Resultat auf dem Fenster 'main' angezeigt werden.
Nun führt das Programm das schon aus bevor ich den Button drücke und darum ist das Resultat auch 0 und bleibt 0.
Kann mir hier einer einen Tip geben?
Viiiieln Dank!
Gruss
Sascha
Hier der Code:
Code: Alles auswählen
import tkinter
def positiv():
popup = tkinter.Tk()
popup.title("Prosit")
popup.geometry("500x80+200+200")
antwort = tkinter.Label(popup, font = "verdana 18 bold", text="Super! zum Wohl!")
b6 = tkinter.Button(popup, font = "verdana", text = "Ende", command = popup.destroy)
b6.place(x=250, y=70, anchor="s")
antwort.pack()
popup.mainloop()
def submit_res(wert):
anzeige = str(wert)
resultat = tkinter.Label(main, font = "verdana 12 bold", text="Anzahl Geschmackspunkte: " + anzeige)
resultat.place(x=250, y=80, anchor="center")
def vote():
vote = tkinter.Tk()
vote.title("vote for taste")
vote.geometry("190x250+900+300")
scalewert = tkinter.IntVar()
vote_scale = tkinter.Scale(vote, width =20, length=200,
orient="vertical", from_=0, to=100,
resolution=10, tickinterval=20, label="Geschmackspunkte",
variable=scalewert)
vote_scale.pack()
b5 = tkinter.Button(vote, text = "submit", command = submit_res(scalewert.get()))
b5.pack()
vote.mainloop()
def negativ():
antwort = tkinter.Label(main, font = "verdana 10 bold", text="Tja... Schade...")
antwort.place(x=250, y=80, anchor="center")
main = tkinter.Tk()
main.title('Weintest')
main.geometry("500x400+300+180")
welcome = tkinter.Label(main, anchor ="center", font = "verdana", text="Willkommen Gast!\n Möchten Sie ein Glas Wein?")
welcome.place(x = 250, y=30, anchor="center")
b = tkinter.Button(main, font = "verdana", text = "Ende", command = main.destroy)
b.place(x=250, y=350, anchor="s")
b2 = tkinter.Button(main, padx = "10", font= "verdana", text = "ja, bitte!", command = positiv)
b2.place(x=170, y=190, anchor="center")
b3 = tkinter.Button(main, padx = "10", font = "verdana", text = "nein danke!", command = negativ)
b3.place(x=350, y=190, anchor="center")
b4 = tkinter.Button(main, padx = "10", font = "verdana", text = "Vote for taste", command = vote)
b4.place(x=250, y=260, anchor="center")
main.mainloop()