Привет, я готовлю графический интерфейс для проекта, но, к сожалению, я не могу сразу ввести конкретный виджет с помощью цифровой клавиатуры. Если я нажму число на цифровой клавиатуре сенсорного экрана, цифра появится в обоих виджетах. Как я могу изменить это, что я могу ввести только цифру в виджете сразу? Я хотел попробовать метод фокуса, но не очень получилось...
Спасибо за вашу помощь.
Вот мой код:
# globally declare the expression variable
expression = ""
# Function to update expression
# in the text entry box
def press(num):
# point out the global expression variable
global expression
# concatenation of string
expression = expression + str(num)
# update the expression by using set method
equation1.set(expression)
equation2.set(expression)
# Function to clear the contents
# of text entry box
def clear():
global expression
expression = ""
equation1.set("")
equation2.set("")
#create GUI
# Driver code
if __name__ == "__main__":
# create a GUI window
gui = Tk()
gui.title("GUI")
equation1 = StringVar()
equation2 = StringVar()
equation1.set("")
equation2.set("")
#Label 1
label1 = tkinter.Label(text ="Pumpenhöhe 1 [cm]")
label1.grid (row =0 , column =0 , padx = xdis , pady = ydis )
#Eingabefeld 1 definieren
eingabe1 = tkinter.Entry(gui, textvariable=equation1, width=4, bg ='#ffffff')
eingabe1.grid(row=0, column=1, padx=xdis, pady = ydis)
#Label 2
label2 = tkinter.Label (text ="Pumpenhöhe 2 [cm]")
label2.grid(row=1,column =0 , padx = xdis ,pady = ydis)
#Eingabefeld 2
eingabe2 = tkinter.Entry(gui, textvariable=equation2, width=4, bg ='#ffffff')
eingabe2.grid(row=1, column=1, padx=xdis, pady = ydis)
#button obj on framework to send values
set_setpoints = tkinter.Button(text ="Send", command = set_setpoints)
set_setpoints.grid(row=2, column=2, padx= xdis, pady = ydis)
#create exit button
ex_bt = tkinter.Button(gui, text='Exit', command=gui.destroy)
ex_bt.grid(row=7, column=2, sticky=tkinter.W, padx=xdis, pady=ydis)
#buttons for numpad
button1 = Button(gui, text=' 1 ',
command=lambda: press(1), height=1, width=7)
button1.grid(row=3, column=0)
button2 = Button(gui, text=' 2 ',
command=lambda: press(2), height=1, width=7)
button2.grid(row=3, column=1)
button3 = Button(gui, text=' 3 ',
command=lambda: press(3), height=1, width=7)
button3.grid(row=3, column=2)
button4 = Button(gui, text=' 4 ',
command=lambda: press(4), height=1, width=7)
button4.grid(row=4, column=0)
button5 = Button(gui, text=' 5 ',
command=lambda: press(5), height=1, width=7)
button5.grid(row=4, column=1)
button6 = Button(gui, text=' 6 ',
command=lambda: press(6), height=1, width=7)
button6.grid(row=4, column=2)
button7 = Button(gui, text=' 7 ',
command=lambda: press(7), height=1, width=7)
button7.grid(row=5, column=0)
button8 = Button(gui, text=' 8 ',
command=lambda: press(8), height=1, width=7)
button8.grid(row=5, column=1)
button9 = Button(gui, text=' 9 ',
command=lambda: press(9), height=1, width=7)
button9.grid(row=5, column=2)
button0 = Button(gui, text=' 0 ',
command=lambda: press(0), height=1, width=7)
button0.grid(row=6, column=0)
clear = Button(gui, text='Clear',
command=clear, height=1, width=7)
clear.grid(row=6, column='1')
Decimal= Button(gui, text='.',
command=lambda: press('.'), height=1, width=7)
Decimal.grid(row=6, column=2)
gui.mainloop()