[英]Python tkinter creating rectangle error
我試圖在c.create_rectangle(x, y, x2, y2, fill=fill_, outline=outline_)
畫布上創建一個矩形,我正在使用的代碼行是這樣的: c.create_rectangle(x, y, x2, y2, fill=fill_, outline=outline_)
。 當我運行代碼時,所有變量都定義為c,是canvas變量,其余數字和顏色名稱,會發生以下錯誤:無效的命令名稱“ .130125072”(此數字是隨機的),並牢記所有參數I給定的是整數,我不知道為什么會發生此錯誤。 如果您能給我答案為什么不起作用,我將非常感謝。 提前致謝。
tkinter的工作方式:
create_rectangle
添加一個矩形,但不繪制它 mainloop
一切都會顯示 這會給你一個矩形
from tkinter import Tk, Canvas, mainloop
c = Canvas(Tk(), width=200, height=100)
c.pack()
c.create_rectangle(50, 25, 150, 75, fill="red", outline="red")
mainloop()
如果你想使用Tkinter的命令行,有討論, 這里有關如何配置它,但它看起來很復雜。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.