前提・実現したいこと
python3.8を使用しています。OSはwindows10です。
ダイエットやバルクアップを目的とする人に、基礎代謝や必要摂取カロリーの計算ができる
ツールの作成をしています。以下の4step構成で考えています。
step1:目的(ダイエット、バルクアップ)の選択
step2:体重、体脂肪率を入力
step3:メンテナンスカロリーと必要摂取カロリーの算出
step4:PFCバランスの算出
発生している問題・エラーメッセージ
step1の目的選択ボタンが配置できないです。
目的を選択した際に、step2に進むためボタンを削除したいです
Traceback (most recent call last): File "C:\Users\phant\OneDrive\デスクトップ\python_game\fitnes.py", line 49, in <module> draw_button() File "C:\Users\phant\OneDrive\デスクトップ\python_game\fitnes.py", line 29, in draw_button btn1 = cvs.create_blk(350, 200, blk=button1) AttributeError: 'Canvas' object has no attribute 'create_blk'
コード
cursor_x = 0 cursor_y = 0 mouse_x = 0 mouse_y = 0 mouse_c = 0 def mouse_move(e): global mouse_x, mouse_y mouse_x = e.x mouse_y = e.y def mouse_press(e): global mouse_c mouse_c = 1 def draw_txt(txt, x, y, siz, col, tg): fnt = ("Times New Roman", siz, "bold") cvs.create_text(x+2, y+2, text=txt, fill="black", font=fnt, tag=tg) cvs.create_text(x, y, text=txt, fill=col, font=fnt, tag=tg) def draw_button(): draw_txt("目的を選択してください", 450, 60, 30, "black", "TITLE") button1 = tkinter.Button(root, text="バルクアップ", font=("Times New Roman", 20), command=click_btn1,fg="black") btn1 = cvs.create_blk(350, 200, blk=button1) button2 = tkinter.Button(root, text="ダイエット", font=("Times New Roman", 20), command=click_btn2,fg="black") btn2 = cvs.create_dy(365, 300, dy=button2) def click_btn1(): cvs.delete("TITLE") canvas.delete("btn1") def click_btn2(): cvs.delete("TITLE") root = tkinter.Tk() root.title("カロリー計算機") root.resizable(False, False) #ウィンドウサイズを変更できなくする root.bind("<Motion>", mouse_move) root.bind("<ButtonPress>", mouse_press) cvs = tkinter.Canvas(root, width=900, height=600, bg="white") #キャンバス部品 cvs.pack() #キャンバスの配置 draw_button() root.mainloop()
試したこと
button.placeを使えば、ボタンの配置はできるのですが、
削除できなかった為、cvs.createにbuttonの変数を入れましたが、
次はボタンが配置できなくなりました。
回答1件
あなたの回答
tips
プレビュー