Pok*_*_SL 8 text tkinter python-3.x
我已经多次尝试将文本添加到我的画布,但它只是通过单击按钮或在画布外部添加它.或者它会弹出一个单独的框.使用以下代码 -
def text():
canvas.create_text(100,10,fill="darkblue",font="Times 20 italic bold",text="Click the bubbles that are multiples of two.")
canvas.update
Run Code Online (Sandbox Code Playgroud)
它从来没有奏效.所以我的问题是如何在画布中添加文字以开始游戏?
Bry*_*ley 16
首先,第一段代码不起作用,因为您没有名为的变量canvas.self.canvas但是,你有一个叫.当我self.canvas在第一段代码中使用并将其添加到工作程序时,文本显示就好了.
另外,在你的第一段代码中canvas.update.这绝对没有效果,因为你没有尾随括号.如果你修复它会起作用,但它真的没用.输入事件循环后,文本将立即显示.
您需要做的就是在创建画布后立即添加一行:
self.canvas = Canvas(root, width=800, height=650, bg = '#afeeee')
self.canvas.create_text(100,10,fill="darkblue",font="Times 20 italic bold",
text="Click the bubbles that are multiples of two.")
Run Code Online (Sandbox Code Playgroud)