So I am having a few problems with my code right now, so instead of creating a separate question for each, I figured I'd just toss them all together.
1) If statement broken
I have a dictionary set up as basically a reverse list. I made it because I needed a variable of sorts where I would input a value, say 'dog' and it would spit out an index value. (If you know a simpler way to do this, please let me know)
Anyway, I have two if statements set up to basically filter through where to send data about the dictionary. For example, lets say the dictionary has 8 items. 0-3 are canines, and 4-7 are felines.
if (animalCode >= 0) and (animalCode < 4):
#stuff for canines
elif (animalCode >= 4) and (animalCode < 8):
#stuff for felines
else:
print("How did you get here?")
Obviously the else is there as error checking, but when I send values that should meet the if criteria of the elif
they pass through the else. I feel like this problem is a simple one that I am just too tired to see at the moment.
2) Tkinter Buttons are running command code when the program compiles, not when they are pressed
Same program as with the above problem, only different part of it. I have a Tkinter GUI screen with Buttons on it. Each button has as it's creation line:
btnSmallDog = ttk.Button(self, text="Small Dog", command = animal.Input("SMALL DOG"))
Obviously not every button is the same, some are Medium Dog
, Large Cat
, etc. What is suppose to happen, is when a button is clicked, the Input()
method, which is in a different class, takes the input, finds out which value that label has in the dictionary, and pass it through. Obviously, this should only happen when the button is actually clicked. However, when I run the module, it executes (or at least attempts to) the command
of each button. And when the interface fully loads, the Buttons are inert and do nothing.
I know the mainloop
is working, because I have another part of the interface that updates every second, and that's running perfectly fine.ff
Aucun commentaire:
Enregistrer un commentaire