TKinterで簡易UIを作る
Raspberry Piのモニターから文字入力させるため、TKinterでUIを作った。
ボタンの色が、どうオプション設定してもうまくできないのが気になる。。
が、はまるポイントはそれぐらい。
今、3.5インチモニター+キーボード+マウスで進めているが、ごちゃごちゃしているので。
モニターのタッチパネル+ソフトウェアキーボードでやるなら、7インチないと厳しいだろうか。など。紆余曲折。
import tkinter as tk
from tkinter import messagebox
class Tkinter_app(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.create_widgets()
def create_widgets(self):
self.input_box=tk.Entry(width=30)
self.input_box.grid(row=0,column=0,columnspan=4, padx=5, pady=20,sticky=(tk.N, tk.S, tk.E, tk.W))
self.clear_btn=tk.Button(width=5, fg='#696969')
self.clear_btn["text"]="クリア"
self.clear_btn["command"]=self.clear_input_value
self.clear_btn.grid(row=1,column=1,padx=5, pady=10,sticky=(tk.N, tk.S, tk.E, tk.W))#,sticky=(tk.N, tk.S, tk.E, tk.W)
self.exec_btn=tk.Button(width=5,fg="#ff6347")
self.exec_btn["text"]="実行"
self.exec_btn["command"]=self.execute_input_value
self.exec_btn.grid(row=1,column=2,padx=5, pady=10,sticky=(tk.N, tk.S, tk.E, tk.W))#,sticky=(tk.N, tk.S, tk.E, tk.W)
def clear_input_value(self):
self.input_box.delete(0, tk.END)
def execute_input_value(self):
msg = self.input_box.get()
if len(msg)>0:
messagebox.showinfo("Now Playing..", msg)
root = tk.Tk()
root.title("電光掲示板")
root.geometry("480x320")
root.config(bg="#f5f5f5")
app=Tkinter_app(master=root)
app.grid(column=0, row=1)
app.mainloop()
下記、参考にさせていただきました。