尝试基于 x 和 y 坐标制作一个简单的绘图程序,我正在使用一个函数在一次调用中绘制和修改坐标,而没有实际使用全局变量为函数本身赋予 valuea 以供函数修改,但它仍然看起来好像我已经给了它实际的直接输入。
在以前的版本中,我通过使用一个类来记住各个类的悬挂坐标和函数来进行绘图,但在这种情况下,输入方法略有不同,因为我使用的是按钮的缩放小部件而不是按钮和正如我之前提到的,我确实尝试在两个程序中使用全局变量,但在其中任何一个程序中都不起作用。
from tkinter import *
win=Tk()
win.title("Etch a Schetch")
win.configure(background="grey")
win.configure(bd=5)
global xa
xa=0
global ya
ya=0
def MOVE():
tabla.create_line(xa,ya,sx.get(),sy.get())
xa=sx.get()
ya=sy.get()
tabla=Canvas(win,width=300,height=300)
sx=Scale(win,from_=0,to=300,length=300,orient="horizontal",command=MOVE)
sy=Scale(win,from_=0,to=300,length=300,command=MOVE)
ex=Button(win,text="Exit",command=exit)
tabla.grid(row=1,column=1)
sx.grid(row=2,column=1)
sy.grid(row=1,column=2)
ex.grid(row=2,column=2)
win.mainloop()
如果它可以工作,它会有点像蚀刻草图。
梵蒂冈之花
相关分类