0
0

More than 1 year has passed since last update.

Python tkinterを使ってボタン描画

Posted at

目的:
日経ソフトウェア1月号
「Pythonで将棋アプリを作ろう ー前編ー」に載っている
canvasウィジェットのテストプログラムを写経し動かしてみました。

環境:
Mac OS 13.2.1   
Intel Core i7
Python 3.11

プログラム:

#Canvasのテストプログラム その1
import tkinter

#Botton-1 イベント時のイベントハンドラ
def canvas_click(event):
xa = event.x
ya = event.y
canvas.create_rectangle(xa, ya, xa + 10, ya + 10, fill="Red")

root = tkinter.Tk() #window
root.geometry("640x480") #window size

#キャンバス作成
canvas = tkinter.Canvas(root, width=640, height=480)
canvas.pack() #キャンバスの配置

#Botton-1 イベント時のイベントハンドラを指定
canvas.bind("", canvas_click)
root.mainloop()

実行結果:

canvas上に赤ボタンを描画することができました。

スクリーンショット 2023-04-28 18.13.58.png

参考文献:
日経ソフトウエア 2023年1月号
https://info.nikkeibp.co.jp/media/NSW/atcl/mag/111700045/

0
0
0

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