0
私はtkinterを使ってGUIを作成しています。ウィンドウ内のボタンで何らかの方法で目と顔を変更したいと思っています。サークルやラインを変更する機能を定義するのに問題があります。私はcreate_line
に電話をしてキャンバスで図面を変えることができると思った。私はdefine
ステートメントを自分のプログラムの一番下に移動しようとしましたが、w
を定義した後には運がありません。私はエラーが発生する'App' object has no attribute 'create_line'
私は非常にPythonに新しいので、任意のフィードバックをいただければ幸いです。フレーム内のキャンバスを変更するためのtkinterボタンコマンドの定義
# import tkinter
from tkinter import *
# define a new class
class App:
# define a command talk
def talk(self):
print("Talk button clicked...")
#w.self.create_line(45, 100, 90, 110)
# window of the GUI
def __init__(self, master):
# parent window
frame = Frame(master, bg = "#76F015")
# organizes the widgets into blocks
frame.pack()
# define a button in the parent window
self.button = Button(frame, text = "Talk", highlightbackground = "#D4D6D3",
fg = "black", command = self.talk)
self.button.pack(side = RIGHT)
# define a canvas
w = Canvas(frame, width = 125, height = 175, bg = "#76F015")
w.pack()
# draw a mouth
w.create_line(45, 100, 85, 100)
# run the main event loop
root = Tk()
app = App(root)
root.mainloop()
あなたはトラブルの種類を言う必要があります。試してみると、モディファイアボタンが1つだけの方が良いでしょう。上に戻るhttps://stackoverflow.com/help/mcve –