Comments (4)
@sim2511 Button should be focused first.
Use .focus()
before detecting the pressing action.
...
self.button.focus()
Note that every time you need to focus the button whenever you want to listen key events from this button.
from customtkinter.
Hello @dipeshSam thanks for your reply
i tried but still not works, i'm on 5.2.0 customtkinter version, the focus method just return "none"
class W1(customtkinter.CTk):
def __init__(self):
super().__init__()
customtkinter.set_appearance_mode("Light")
self.geometry("550x150")
self.title("W1")
self.button = customtkinter.CTkButton(self, text="W1", command=self.open_w2)
self.button.grid(row=0, column=0)
self.button.focus()
self.button.bind('<Return>', self.open_w2)
def open_w2(self):
print('hello')
from customtkinter.
I found a solution, hope it can help someone else ! (add event=None in your function parameter) and try with bind_all method instead of bind, it worked for me:
class W1(customtkinter.CTk):
def __init__(self):
super().__init__()
customtkinter.set_appearance_mode("Light")
self.geometry("550x150")
self.title("W1")
self.button = customtkinter.CTkButton(self, text="W1", command=self.open_w2)
self.button.grid(row=0, column=0)
self.bind_all('<Return>', self.open_w2)
def open_w2(self, event=None):
print('hello')
if __name__ == "__main__":
root_1 = W1()
root_1.mainloop()
from customtkinter.
also work with bind, the event parameters is the only thing you need to do
class W1(customtkinter.CTk):
def __init__(self):
super().__init__()
customtkinter.set_appearance_mode("Light")
self.geometry("550x150")
self.title("W1")
self.button = customtkinter.CTkButton(self, text="W1", command=self.open_w2)
self.button.grid(row=0, column=0)
self.bind('<Return>', self.open_w2)
def open_w2(self, event=None):
print('hello')
if __name__ == "__main__":
root_1 = W1()
root_1.mainloop()
from customtkinter.
Related Issues (20)
- dynamic output terminal HOT 1
- Typo error in CtkComboBox Methods
- .
- add feature TextBox HOT 5
- add feature textbox typing
- scrollable frame destroy() still hasn't fixed yet
- Request: Separator
- segmented button command error HOT 1
- Vertical Progressbar rendering bug HOT 2
- Scrollable Frame HOT 1
- button anchor
- Make Scrollable frame and option menu better HOT 2
- Combobox bind in keyboard keys Dropdown menu
- How do I add an image to a button? HOT 1
- CTkTabview allowing to change tabs when CTkTabview_obj.configure(state="disable")
- Issues with crashing - tcl86t.dll on Customtkinter 5.2.2
- Adding label inside progress bar
- Remove Border OptionMenue HOT 1
- Label automatically gives y-padding using grid
- Unable to update text with .configure(text='new text') HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from customtkinter.