同じウィンドウに作成した数字キーを用いて、選択したentryボックスに入力したいのですが、現在は1番上のentryボックスにしか数字を入力できていません。
2番目【2】のentryボックスにも入力するにはどうしたら良いでしょうか。
タッチパネルを想定しているのでペンで選択したentryボックスに数字を入力したいです。
import tkinter as tk from tkinter import ttk import cv2 import numpy as np import datetime import os from tkinter import filedialog from tkinter import messagebox class Win5(tk.Frame): def __init__(self,master): super().__init__(master) global exp exp = " " # global variable self.grid(row=0,column=0) self.master.geometry("+10+50")#横×縦 self.master.title("画面") self.create_widgets() self.master.bind_all("<Button-1>", lambda e: self.focus(e)) def focus(self,event): widget = self.master.focus_get() print(widget) def press(self,num): global exp exp=exp + str(num) self.equation1.set(exp) def clear(self): global exp exp = " " self.equation1.set(exp) def create_widgets(self): label_sikiichi=tk.Label(self,text='【1】',font=("",17)) label_sikiichi.grid(row=0,column=0) self.equation1 = tk.StringVar() self.entry_gain = tk.Entry(self,width=20,font=("",17),textvariable = self.equation1) self.entry_gain.grid(row=1,column=0) label_sikiichi2=tk.Label(self,text='【2】',font=("",17)) label_sikiichi2.grid(row=2,column=0) self.entry_rokou = tk.Entry(self,width=20,font=("",17)) self.entry_rokou.grid(row=3,column=0) #適用ボタンの作成 button1 = tk.Button(self,text='OK',width=10,relief="ridge",font=("",18)) button1.grid(row=4,column=1) q = ttk.Button(self,text = '0' , width = 7, command = lambda : self.press('0')) q.grid(row = 5 , column = 2, ipadx = 6 , ipady = 10) w = ttk.Button(self,text = '1' , width = 7, command = lambda : self.press('1')) w.grid(row = 5 , column = 3, ipadx = 6 , ipady = 10) E = ttk.Button(self,text = '2' , width = 7, command = lambda : self.press('2')) E.grid(row = 5 , column = 4, ipadx = 6 , ipady = 10) R = ttk.Button(self,text = '3' , width = 7, command = lambda : self.press('3')) R.grid(row = 6 , column = 2, ipadx = 6 , ipady = 10) T = ttk.Button(self,text = '4' , width = 7, command = lambda : self.press('4')) T.grid(row = 6 , column = 3, ipadx = 6 , ipady = 10) Y = ttk.Button(self,text = '5' , width = 7, command = lambda : self.press('5')) Y.grid(row = 6 , column = 4, ipadx = 6 , ipady = 10) U = ttk.Button(self,text = '6' , width = 7, command = lambda : self.press('6')) U.grid(row = 7 , column = 2, ipadx = 6 , ipady = 10) I = ttk.Button(self,text = '7' , width = 7, command = lambda : self.press('7')) I.grid(row = 7 , column = 3, ipadx = 6 , ipady = 10) O = ttk.Button(self,text = '8' , width = 7, command = lambda : self.press('8')) O.grid(row = 7 , column = 4, ipadx = 6 , ipady = 10) P = ttk.Button(self,text = '9' , width = 7, command = lambda : self.press('9')) P.grid(row = 8 , column = 2, ipadx = 6 , ipady = 10) clear = ttk.Button(self,text = 'Clear' , width = 6, command = self.clear) clear.grid(row = 8 , column = 3, ipadx = 7 , ipady = 10) def main(): global root root = tk.Tk() app = Win5(master=root) app.mainloop() root=app=None if __name__ == "__main__": main()
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/02/21 02:49