2

I'm woking on a project of a chatting app, using tkinter, running on python 3.7 and Windows 10 OS. One of the things I would like to add to my app, is an option of opening up the Windows's Touch Keyboard.

Although you can open the keyboard by pressing its button on the taskbar, I would like to give access to it from my app. My idea is to bind an Entry widget, used as the console line of my app, to an event, that whenever it occurrs, it makes the Touch Keyboard to pop up. The event I'll probably be using is '<FocusIn>', which means that the keyboard focus is moved to it. Here is a quick example of the mechanics:

def open_keyboard(event):
    pass # open the Touch Keyboard


root = Tk()
console = Entry(root, font=('Verdana', 14), cursor='pencil', bg='red', fg='yellow') # creating console
console.pack()

console.bind('<FocusIn>', open_keyboard) # bind the console to the event

root.mainloop()

NOTICE: The Touch Keyboard IS NOT the On-Screen Keyboard. I don't want to use this keyboard, because it poppes up as a new window and not as a Toplevel window, which blocks my chatting app. More Importantly, it has no Emoji keyboard :) A simple way to open the On-Screen Keyboard, is by running the following lines:

import os

os.system('osk')

I've been searching all over the internet for a solution, but they're all seem to be handling the On-Screen Keyboard. If someone knows how to help me or divert me to a source that explains how to handle it, he's more than welcomed to do so, because I'm stuck right now :/

1 Answers1

1

Try this (explanation in code comment)

I think this directory will be the same on almost all Windows installations, still I'm looking for a way to make it path independent.

from tkinter import *
import os

root = Tk()

def callback(event):
    # so the touch keyboard is called tabtip.exe and its located in C:\Program Files\Common Files\microsoft shared\ink
    # here we run it after focus
    os.system("C:\\PROGRA~1\\COMMON~1\\MICROS~1\\ink\\tabtip.exe")

frame = Frame(root, width=100, height=100)
frame.pack()

addressInput = Entry(frame, font = "Verdana 20 ", justify="center")
addressInput.bind("<FocusIn>", callback)
addressInput.pack()

root.mainloop()
Thaer A
  • 2,243
  • 1
  • 10
  • 14
  • 1
    Hey, it works good excpet of one thing: when I close the keyboard I can't open it again, unless I minimize the window and expand it again. In other words, it recognizes only the first event that occurrs, and not the ones following it. I tries to change the event to (an event of mouse-click) but it appears to be the same. Do you have any idea how to solve it? – Roei Duvdevani Apr 20 '20 at 19:37
  • @RoeiDuvdevani Its not the problem with `event`. Bindings work all good. – Delrius Euphoria Apr 07 '21 at 14:50
  • 1
    In-order to deal with the keyboard not showing up after closing it, make sure to end the process before starting it up again: **os.system('wmic process where name="TabTip.exe" delete')** – OmerSS Apr 16 '21 at 19:59