Pick a name whichĮxpresses what the variable means. That the ‘t’ key is currently held down? It affects how the code behavesĪlso, please pick a better name than “variable”. What does “keyboard.is_pressed” measure? That someone typed a ‘t’, or I’m wondering if this is the start/stop thing you allude to in your next Want your toggle to activate a “clock madly indefinitely” mode? print(toggle) This clicks the button every time toggle is true. “^” works because Booleans are actually implemented as a type of int,īut it is normally a poor way to think about them. You really want the logical “not” operator as above. The “^” operator is a bitwise operator - it is a numeric operation, notĪ logical one. This is better written: toggle = not toggle You can just write: variable = keyboard.is_pressed('tab') Want toggle to change when you press ‘t’ (or ‘tab’, it was ‘t’ before). Don’t do that! It resets the toggle at the top of the loop.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |