简体   繁体   中英

Tkinter Canvas object not appearing

I was trying to add a draggable window object in the tkinter canvas. It worked when there wasn't the 'obj' function but I want it to be there for specific purposes. 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.

Try adding main() as the last line of your obj() definition.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM