オープンコードのプログラムを実行したいです。

python

1# Copyright 2021 Google LLC2#3# Licensed under the Apache License, Version 2.0 (the "License");4# you may not use this file except in compliance with the License.5# You may obtain a copy of the License at6#7# http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# distributed under the License is distributed on an "AS IS" BASIS,11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12# See the License for the specific language governing permissions and13# limitations under the License.14 15import tkinter as tk 16from tkinter import *17from tkinter import ttk 18 19import numpy as np 20from PIL import Image, ImageTk 21 22 23class DemoGUI:24 25 def update_canvas(self):26 pil_im = Image.fromarray(self.frame_rgb_canvas).resize((480, 480))27 self.photo = ImageTk.PhotoImage(image=pil_im)28 self.canvas.create_image(0, 0, image=self.photo, anchor=NW)29 30 def __init__(self):31 super().__init__()32 33 self.root = tk.Tk()34 self.root.title("GUI")35 36 self.root.geometry("500x630")37 38 self.notebook = ttk.Notebook(self.root)39 40 self.canvas = Canvas(self.root, width=480, height=480)41 self.canvas.pack(expand=True)42 self.frame_rgb_canvas = np.zeros([480, 640, 3]).astype(np.uint8)43 self.update_canvas()44 45 self.TAB1 = Frame(self.notebook, bg="#00766c")46 self.notebook.add(self.TAB1, text='Record')47 self.notebook.bind("<<NotebookTabChanged>>", self.tab_btn_cb)48 49 self.TAB2 = Frame(self.notebook, bg="#00766c")50 self.notebook.add(self.TAB2, text='Play mode')51 self.notebook.pack(expand=2, fill="both")52 53 self.is_play_mode = 054 self.is_recording = False55 56 # ─── RECORD MODE ─────────────────────────────────────────────────57 58 # record button.59 self.record_btn_text = StringVar(self.TAB1, name="record_btn_text")60 self.record_btn_text.set("Record")61 self.is_recording = False62 record_btn = Button(self.TAB1, textvariable=self.record_btn_text, command=self.record_btn_cb).grid(columnspan=2,63 sticky=W)64 65 # name box.66 self.name_box = Entry(self.TAB1, text="Sign name")67 self.name_box.grid(row=2, column=0, sticky=E)68 69 # num recoreds70 self.num_records_text = StringVar(self.TAB1, name="num_records_text")71 num_records_text_box = Label(self.TAB1, textvariable=self.num_records_text).grid(row=0, column=1)72 self.num_records_text.set("num records: 0")73 74 # save button.75 self.save_btn = Button(self.TAB1, text="Save", command=self.save_btn_cb)76 self.save_btn.grid(row=2, column=1, sticky=W)77 78 # ─── PLAY MODE ───────────────────────────────────────────────────79 80 # record button.81 self.record_btn_text = StringVar(self.TAB2, name="record_btn_text")82 self.record_btn_text.set("Record")83 self.is_recording = False84 record_btn_p = Button(self.TAB2, textvariable=self.record_btn_text,85 command=self.record_btn_cb).grid(columnspan=2, sticky=W)86 87 # Show console.88 self.console_box = Text(self.TAB2, bg="#44a18e")89 self.console_box.grid(columnspan=2, sticky=W)90 91 def record_btn_cb(self):92 self.is_recording = not self.is_recording 93 tab_id = self.notebook.index(self.notebook.select())94 if self.is_recording:95 self.record_btn_text.set("Stop")96 self.notebook.tab(not tab_id, state="disabled")97 self.name_box["state"] = DISABLED 98 self.save_btn["state"] = DISABLED 99 100 else:101 self.record_btn_text.set("Record")102 self.notebook.tab(not tab_id, state="normal")103 self.name_box["state"] = NORMAL 104 self.save_btn["state"] = NORMAL 105 106 def tab_btn_cb(self, event):107 self.is_play_mode = self.notebook.index("current")108 109 def save_btn_cb(self):110 pass111 112 113if __name__ == "__main__":114 config_dialog = DemoGUI()115 config_dialog.root.mainloop()

コメントを投稿

0 コメント