#๐Ÿ”’ why is the input not being noticed

62 messages ยท Page 1 of 1 (latest)

vale path
#

am using tkinter and whenever i clicked the button widget it does call the function

split heartBOT
#

@vale path

Python help channel opened

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.

stable rivet
#

Button(root, command=change_resize)

vale path
#

no but that wont allow for the use of two functions

stable rivet
#

then have 1 function that calls 2 functions

vale path
#

also it doesnt work with binf

#

bind

#

for me rn

stable rivet
#

Use <Button> instead of activate

#

you'll also need a parameter in your resize function since bind events pass in an argument

vale path
#

wt paramater

#

parameter

stable rivet
#

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

vale path
#

ok but how does keypress work

stable rivet
vale path
vale path
stable rivet
#

then you bind to <Key>

vale path
#

not working

stable rivet
#

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

vale path
#

so should i use button.focus

#

what does focus do anyways

stable rivet
#

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

vale path
#

so with buttons its wt button ur over>

stable rivet
#

no, buttons don't really have the concept of focus

#

at least not in tkinter

vale path
#

ok

stable rivet
#
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

vale path
#

that works thanks

#

just wondering

#

is this a good source of learning tkinter

stable rivet
#

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

vale path
#

OoO

#

where can i learn that

#

i was trying to learn tkinter cause i was in a course about it

stable rivet
#

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

#

This site is a great resource

vale path
#

thanks

#

have a nice day

stable rivet
#

you too ๐Ÿ™‚

vale path
#

!close

split heartBOT
#
Python help channel closed

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.