Burtski
Burtski

Reputation: 501

Tkinter Popup Keyboard Library

Before I go reinventing the wheel. Is there a (more or less) standard library for a popup keyboard for Tkinter?

I need both a popup number pad (0-9,.,...ect) and a full keyboard (a-Z,A-Z,0-9,.,...etc).

I currently have a nice number pad, but (as usual) my client told me after I got it done that they want a full keyboard as well.

In sort of a second question but same topic. What is the correct way to pop between these two sibling windows so that they both return to the original parent no mater how many times you flip back and forth.

Upvotes: 2

Views: 4014

Answers (1)

Fantilein1990
Fantilein1990

Reputation: 155

I had the same problem and did not find an appropriate solution other than creating (or at least heavily improving) one myself. I used

petemojeiko's virtual keyboard on GitHub

as a starting point for creating my own solution. It needed to be usable in typing a complex password, so it sports keys for lower- and uppercase letters, numerals and (most) symbols a regular keyboard supports.

However, due to the need to fit it on a small screen, I put the numerals and symbols on a third layer (like a symbol-shift). This presented me with basically the same proble you had in the second part of your question (switching between layers).

I solved it by implementing three keyboards (one for each layer) and destroying one specific keyboard as well as the frame containing it and creating a new one each time I wanted to change between those layers (or switch to a different entry widget):

self.frame1.destroy()
self.frame2.destroy()
self.kb.destroy()

self.frame1 = ttk.Frame(self, width=480, height=280)
self.frame1.pack(side="top", pady=30)
self.kb = vKeyboard(attach=self.entry1,
                   x=self.entry1.winfo_rootx(),
                   y=self.entry1.winfo_rooty() + self.entry1.winfo_reqheight(),
                   keysize=self.keysize,
                   parent=self.frame1,
                   controller=self.controller,
                   enterAction=self.enterAction)

I'm still new to Python/Tkinter, so someone else might be able to do it without destroying the parent frames, but this worked for me (and even on the limited ressources of a Raspberry Pi, it didn't cause any problems).

Upvotes: 1

Related Questions