#๐ why is the input not being noticed
62 messages ยท Page 1 of 1 (latest)
@vale path
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
use the command parameter to pass in a callback
Button(root, command=change_resize)
no but that wont allow for the use of two functions
then have 1 function that calls 2 functions
Use <Button> instead of activate
you'll also need a parameter in your resize function since bind events pass in an argument
you can name it whatever you want, but most people would use event
it contains information about the event, like which mouse button was used to click, and position on screen
I think your best option though is to just call 2 functions from 1
import tkinter as tk
def on_button_click():
function_1()
function_2()
root = tk.Tk()
tk.Button(text="Test", command=on_button_click).pack()
root.mainloop()
you're making it way more complicated than it needs to be
ok but how does keypress work
What are you trying to do?
its just cause am following a tutorial
trying to make it so if the key a is pressed over the button it calls the function change_resize
then you bind to <Key>
not working
I don't think you can bind a button to Key actually since buttons don't really take focus
<Key> only works on something in focus
no, bind to root and then check what widget is under your cursor
one sec
Only 1 widget can be in focus at a time
imagine you had 5 Entry
you can't type in all 5 at the same time
the one you're currently typing in has Focus
so with buttons its wt button ur over>
ok
import tkinter as tk
def on_button_click():
print("Button Clicked")
def resize(event):
x,y = root.winfo_pointerxy()
widget = root.winfo_containing(x,y)
if widget == btn and event.char == 'a':
print("RESIZE")
root = tk.Tk()
btn = tk.Button(text="Test", bg='#7788cd', command=on_button_click, padx=15, pady=15)
btn.pack()
root.bind('<Key>', resize)
root.mainloop()
try running this code
if you click the button, you'll get the Button Clicked print from that function
if you hover your mouse over the button and press A on your keyboard, you'll get the resize print
that works thanks
just wondering
is this a good source of learning tkinter
In this tutorial, you'll learn about the Tkinter event binding and how to use it to associate a function to an event of a widget.
Looks ok to me. Pretty much everything I know about tkinter has come from helping people in these threads
If you really want to sink your teeth into a good UI, learn PySide
OoO
where can i learn that
i was trying to learn tkinter cause i was in a course about it
it's decent as an intro to GUI
if all you want is a simple UI with some buttons, it's fine
pyside is more advanced which means it can be a bit harder for a beginner, but it's far more powerful and customizable
Start building Python GUIs with PySide2. A step-by-step guide to creating your first window application, perfect for beginners looking to explore PySide2 development. Following this simple outline you can start building the rest of your app. In this tutorial we'll learn how to use PySide to create desktop applications with Python.
This site is a great resource
you too ๐
!close
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.