Tkinter ein Nummernblock und mehrere Entries (Anfänger)
Verfasst: Dienstag 5. Januar 2021, 15:05
Hallo bin Anfänger und muss ein Projekt machen. Hierbei verwende ich einen Raspberry und ein Display von JOY-IT. Bei meinem Programm habe ich zwei Entries (E1 und E2) und sobald auf eines der beiden Entries geclickt worden ist rufe ich die Funktion "clicker" auf, dann öffnet sich ein neues Fenster und darin befinden sich Buttons (Nummernblock). Jedoch ist mein Problem, dass sobald man eine Zahl in ein Entry schreibt, wird gleichzeitig in das andere Entry die selbe Zahl geschrieben. Somit meine Frage: Wie kann ich sagen, dass der Fokus auf das angeclickte Entry liegt und bei dem anderen keine Zahlen eingeben werden (erst wenn dieses angeclickt worden ist)? :conf:
Danke im Voraus! Im Anhang befindet sich mein Programm.
Mit freundlichen Grüßen,
FloMatt
Danke im Voraus! Im Anhang befindet sich mein Programm.
Mit freundlichen Grüßen,
FloMatt
Code: Alles auswählen
from tkinter import *
import os
App = Tk()
App.config(background = "white")
App.geometry("1280x800")
def clicker(*args): #Tastatur
App5 = Toplevel()
App5.title("Bitte Maß einegben")
App5.config(background = "white")
App5.geometry("320x420+640+340")
B7 =Button(App5, text ="7",font= ("Helvetica",20), borderwidth=3, command=lambda: [button_click(7),button_click2(7)])
B7.place(x=10,
y=10,
width=100,
height=100)
B8 =Button(App5, text ="8",font= ("Helvetica",20), borderwidth=3, command=lambda: [button_click(8),button_click2(8)])
B8.place(x=110,
y=10,
width=100,
height=100)
B9 =Button(App5, text ="9",font= ("Helvetica",20), borderwidth=3, command=lambda: [button_click(9),button_click2(9)])
B9.place(x=210,
y=10,
width=100,
height=100)
B4 =Button(App5, text ="4",font= ("Helvetica",20), borderwidth=3, command=lambda: [button_click(4),button_click2(4)])
B4.place(x=10,
y=110,
width=100,
height=100)
B5 =Button(App5, text ="5",font= ("Helvetica",20), borderwidth=3, command=lambda: [button_click(5),button_click2(5)])
B5.place(x=110,
y=110,
width=100,
height=100)
B6 =Button(App5, text ="6",font= ("Helvetica",20), borderwidth=3, command=lambda: [button_click(6),button_click2(6)])
B6.place(x=210,
y=110,
width=100,
height=100)
B1=Button(App5, text ="1",font= ("Helvetica",20), borderwidth=3, command=lambda: [button_click(1),button_click2(1)])
B1.place(x=10,
y=210,
width=100,
height=100)
B2=Button(App5, text ="2",font= ("Helvetica",20), borderwidth=3, command=lambda: [button_click(2),button_click2(2)])
B2.place(x=110,
y=210,
width=100,
height=100)
B3=Button(App5, text ="3",font= ("Helvetica",20), borderwidth=3, command=lambda: [button_click(3),button_click2(3)])
B3.place(x=210,
y=210,
width=100,
height=100)
BP =Button(App5, text =".",font= ("Helvetica",20), borderwidth=3, command=lambda: [button_click("."),button_click2(".")])
BP.place(x=10,
y=310,
width=100,
height=100)
B0 =Button(App5, text ="0",font= ("Helvetica",20), borderwidth=3, command=lambda: [button_click(0),button_click2(0)])
B0.place(x=110,
y=310,
width=100,
height=100)
C =Button(App5, text ="C",font= ("Helvetica",20), borderwidth=3, command= button_clear)
C.place(x=210,
y=310,
width=100,
height=100)
def button_click(number):
current1 = E1.get()
E1.delete(0, END)
E1.insert(0, str(current1)+ str(number))
def button_click2(number):
current2 = E2.get()
E2.delete(0,END)
E2.insert(1, str(current2)+ str(number))
def button_clear():
E1.delete(0, END)
E2.delete(0, END)
E1 = Entry(App,
bg="white",
borderwidth=2,
font=("Hevetica", 22))
E1.bind("<Button-1>", clicker)
E1.place(x=500,
y=180,
width= 200,
height=65)
E2 = Entry(App,
bg="white",
borderwidth=2,
font=("Hevetica", 22))
E2.bind("<Button-1>",clicker)
E2.place(x=500,
y=280,
width= 100,
height=65)
App.mainloop()