[英]Tkinter Canvas object not appearing
I was trying to add a draggable window object in the tkinter canvas. 我试图在tkinter画布中添加可拖动的窗口对象。 It worked when there wasn't the 'obj' function but I want it to be there for specific purposes. 当没有'obj'函数时,它起作用了,但是我希望它可以用于特定目的。 Now, when I try to do it, no button pops up on the canvas. 现在,当我尝试执行此操作时,画布上没有任何按钮弹出。
from tkinter import *
import app
def obj(can,text):
b1 = "up"
xold, yold = None, None
def main():
global aaa
global frame
global text
global drawing_area
drawing_area = can
drawing_area.create_window(50,50,tags='aaa',window=text)
text.bind("<Motion>", motion)
text.bind("<ButtonPress-1>", b1down)
text.bind("<ButtonRelease-1>", b1up)
def b1down(event):
global b1
b1 = "down"
def b1up(event):
global b1, xold, yold
b1 = "up"
xold = None
yold = None
def motion(event):
global frame
global aaa
global text
global drawing_area
if b1 == "down":
global xold, yold
if xold is not None and yold is not None:
drawing_area.move('aaa',event.x,event.y)
xold = event.x
yold = event.y
root = Tk()
drawing_area = Canvas(root,height=500,width=700,bg='Blue')
text=Button(drawing_area,text='Test')
drawing_area.pack()
if __name__ == "__main__":
obj(drawing_area,text)
Your obj
function defines three variables and four functions, but does nothing. 你的obj
函数定义了三个变量和四大功能,但什么都不做。
Try adding main()
as the last line of your obj()
definition. 尝试将main()
添加为obj()
定义的最后一行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.