window = tkinter.Tk()
window.geometry('700x700')
text_eingabe = Entry(window)
text_eingabe.place(x = 250, y = 550)
def coords():
xy = int(text_eingabe.get())
C.create_line(10,10,{xy},200, fill= 'blue')
eingabe_bestätigung = Button(window, text= 'bitte bestätigen', command= coords)
eingabe_bestätigung.place(x = 250, y= 500)
C = Canvas(window, bg = 'white',width= 300, height= 300)
C.place(x= 170, y= 100)
window.mainloop()
问题是我遇到了一个错误,叫做"屏幕距离不好"当我试图将数字放入输入框中,将其"转换"为行的变量时
{xy}
创建一个集合。你只想使用变量,所以正确的代码是:
window = tkinter.Tk()
window.geometry('700x700')
text_eingabe = Entry(window)
text_eingabe.place(x = 250, y = 550)
def coords():
xy = int(text_eingabe.get())
C.create_line(10,10,xy,200, fill= 'blue')
eingabe_bestaetigung = Button(window, text= 'bitte bestätigen', command= coords)
eingabe_bestaetigung.place(x = 250, y= 500)
C = Canvas(window, bg = 'white',width= 300, height= 300)
C.place(x= 170, y= 100)
window.mainloop()