0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

tkinter:タイマー的なもの

Last updated at Posted at 2022-02-15
import tkinter as tk

class Timer:

    def __init__(self):
        self.root = tk.Tk()
        self.message = tk.StringVar()
        self.message.set("Test")
        label = tk.Label(textvariable=self.message, font=('Helvetica', 48))
        label.pack()
        self.count = 0

    def update(self):
        self.count += 1
        self.message.set(str(self.count))
        # self.label.configure(text=label_txt)
        self.root.after(1000, self.update)

    def main(self):
        self.root.after(1000, self.update)  # "Test"を描画させるために1秒後にupdateを呼ぶ
        self.root.mainloop()                # 描画処理が始まり、初期設定した"Test"が描画される


app = Timer()  # インスタンス生成:速やかに終わらせる
app.main()     # メインループ処理:描画やイベント処理を行う

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?