Ok, so i've imported the keyboard in a 2d list for the rows and columns of a standard keyboard. Im just testing it however the "S" key seems to dissapear which is very unusual as the keys are initialised in a for looop.
Below is my code. Thanks in advance
from tkinter import *
KEYS = [["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"], ["A", "S", "D", "F", "G", "H", "J", "K", "L"], ["Z", "X", "C", "V", "B", "N", "M"]]
class CharInput:
def __init__(self, parent):
self.buttons = []
for y in range(len(KEYS)):
for x in range(len(KEYS[y])):
print(KEYS[y][x])
self.buttons.append(Button(parent, text=KEYS[y][x]))
self.buttons[len(self.buttons)-1].bind("<Button-1>", self.clicked)
self.buttons[len(self.buttons)-1].grid(row=y, column=x)
def clicked(self, event):
print("clicked")
event.widget.configure(bg="green")
if __name__ == "__main__":
root = Tk()
CharF = Frame().grid(row=2, column=0)
CharInput(CharF)
F2 = Frame(width=12, height=12).grid(row=1, column=1)
root.mainloop()
CodePudding user response:
I don't know Tkinter in the slightest.. but looked like simple code and I wanted to try to solve the problem.. anyway
from tkinter import *
KEYS = [["Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P"], ["A", "S", "D", "F", "G", "H", "J", "K", "L"], ["Z", "X", "C", "V", "B", "N", "M"]]
class CharInput:
def __init__(self, parent):
self.buttons = []
for y in range(len(KEYS)):
for x in range(len(KEYS[y])):
print(KEYS[y][x], x, y)
self.buttons.append(Button(parent, text=KEYS[y][x]))
self.buttons[len(self.buttons)-1].bind("<Button-1>", self.clicked)
self.buttons[len(self.buttons)-1].grid(row=y, column=x)
print("\n\n")
def clicked(self, event):
print("clicked")
event.widget.configure(bg="green")
if __name__ == "__main__":
root = Tk()
CharF = Frame().grid(row=3, column=0)
CharInput(CharF)
F2 = Frame(width=12, height=12).grid(row=3, column=1)
root.mainloop()
I changed the row= to 3 in both cases
CharF = Frame().grid(row=3, column=0)
CharInput(CharF)
F2 = Frame(width=12, height=12).grid(row=3, column=1)
CodePudding user response:
The reason is that the "s" key is on row 1, column 1 and you also put F2
in row 1, column 1. F2
is thus on top of s
, hiding it from view.