我目前正在学习Python并开始使用ktinter。我现在的目标是创建一个拖放函数来创建按钮并用一条线连接它们。在
到目前为止,我得到的是:
from tkinter import *
class Test:
def __init__(self, master):
X1 = int(input())
Y1 = int(input())
X2 = int(input())
Y2 = int(input())
self.blackLine = Canvas.create_line(X1, Y1, X2, Y2)
convas = Canvas(master)
convas.pack()
button1 = Button(text = "button 1")
button1.configure(width = 0, activebackground = "#D2D2D2", relief = GROOVE)
button1_window = convas.create_window(X1, Y1, anchor=NW, window=button1)
button1.update()
print (button1.winfo_geometry())
button2 = Button(text = "button 2")
button2.configure(width = 0, activebackground = "#D2D2D2", relief = GROOVE)
button2_window = convas.create_window(X2, Y2, anchor=NW, window=button2)
button2.update()
print (button2.winfo_geometry())
现在,正如你可能看到的那样,我正在测试线条绘制,方法是在开始时在整数中输入一些值,然后在button1,2_窗口坐标中使用它们来放置画布上的按钮。现在当我启动程序时,我的问题就出现了。在
一旦我输入了4,4,10,10这4个数字,就会出现一个attributeError这样说:
“AttributeError:'int'对象没有属性''u create'”
我不确定,但我想它是以某种方式使用数字作为字符串的,因此我尝试用int(input))代替普通的input()函数。在
你好
需要使用canvas实例而不是canvas类生成行。为此,必须在画布初始化之后移动它。在
相关问题 更多 >
编程相关推荐