Mar-28-2020, 02:05 PM
Hi everyone,
I'm trying to make a virtual keyboard in python (like Microsoft's on-screen keyboard) however
am experiencing a couple of glitches.
Code (unfinished however the letters are in):
Glitches:
1. In the test line (next to comment), this should print the key clicked. However, it always
prints 'Z'
2. On-screen keyboard window always takes focus, therefore keys cannot be typed into another window
I would be grateful if anyone could help.
I'm trying to make a virtual keyboard in python (like Microsoft's on-screen keyboard) however
am experiencing a couple of glitches.
Code (unfinished however the letters are in):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
from tkinter import * from pynput.keyboard import Key, Controller import string from tkinter.ttk import * letters = list (string.ascii_uppercase) numbers = [ 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] keyboard = Tk() keyboard.title( "Virtual Keyboard" ) keyboard.focus_force() keyboard.attributes( "-topmost" , True ) style = Style() style.configure( "W.TButton" , font = ( "calibri" , 10 , "bold" ), foreground = "red" , background = "black" ) typer = Controller() class Keyboard: def __init__( self ): keyboard.config(bg = "black" ) @classmethod def type_key( cls , key): global typer print ( str (key)) #test line typer. type ( str (key)) class Interface: def __init__( self ): main_funcs = Keyboard() x = 0 y = 0 abc_item = 0 num_item = 0 let = 0 num = 0 for item in letters: Button(keyboard, text = letters[abc_item], width = 5 , style = "W.TButton" , command = lambda : Keyboard.type_key(letters[let - 1 ])).grid(row = x, column = y) if x < 4.33333333 - 2 : x + = 1 else : y + = 1 x = 0 abc_item + = 1 let + = 1 load = Interface() keyboard.mainloop() |
1. In the test line (next to comment), this should print the key clicked. However, it always
prints 'Z'
2. On-screen keyboard window always takes focus, therefore keys cannot be typed into another window
I would be grateful if anyone could help.