Jun-30-2021, 03:04 PM
I am unsure if this is the right forum, but since it concerns a wigdet it seemed appropriate.
In line 26 the line "strength_entry.bind('<Return>', update_score(ab=2))" uses braces behind the calling the function "update_score". If I remove the braces and change the argumetn "ab" to "0" in line 19 I will be able to change the label with the use of the enter button in the GUI. But since I want to be able to expand the number of wigdets with more entry and have them all use the same function I cant let it be written in line 19. I want to be able to expand the library in line 18 later. (The "40" is just a test to see if I could be able to change it.)
To clearify, the function will run one time when I specify which element in the library I want to use, and not run everytime I press enter. Is there a way to write this?
I am learning Python by creating this program, but sometimes i get stuck at stuff like this.
In line 26 the line "strength_entry.bind('<Return>', update_score(ab=2))" uses braces behind the calling the function "update_score". If I remove the braces and change the argumetn "ab" to "0" in line 19 I will be able to change the label with the use of the enter button in the GUI. But since I want to be able to expand the number of wigdets with more entry and have them all use the same function I cant let it be written in line 19. I want to be able to expand the library in line 18 later. (The "40" is just a test to see if I could be able to change it.)
To clearify, the function will run one time when I specify which element in the library I want to use, and not run everytime I press enter. Is there a way to write this?
I am learning Python by creating this program, but sometimes i get stuck at stuff like this.
from tkinter import * import math parent_w = Tk() ability_w = Frame(parent_w) ability_w.grid(row=0, column=0) class AbilityScore: def __init__(self, score): self.score = score def my_score(self): return math.floor(int(self.score - 10) / 2) def update_score(*args, ab): abilities_list = [strength_entry.get(), 40] strength_label.config(text=math.floor((int(abilities_list[ab]) - 10) / 2)) strength_entry = Entry(ability_w, widt=3, font=("Arial", 20), justify=CENTER) strength_entry.insert(0, 0) strength_label = Label(ability_w, font=("Arial", 15), text=AbilityScore(int(strength_entry.get())).my_score()) strength_text = Label(ability_w, text="Strength", font=("Arial", 20)) strength_entry.bind('<Return>', update_score(ab=0)) strength_entry.grid(row=0, column=1) strength_text.grid(row=0, rowspan=2, column=0) strength_label.grid(row=1, column=1) parent_w.geometry("400x250") parent_w.mainloop()