my canvas I small when the size 1680x960

时间:2017-02-16 22:57:26

标签: python tkinter tkinter-canvas

from tkinter import *

root = Tk()

coords=1017,474
frame = Canvas(root, width=1680, height=960)


def cords(event):
    print(event.x,event.y)



def click(event):
    frame.create_line(event.x,event.y,coords)

frame.bind('<B1-Motion>',click)
frame.bind('<Button-1>',cords)


photo=PhotoImage('images.png')
label=Label(frame,image=photo)
label.grid(row=5,)

frame.pack()

root.mainloop()

when I run this code my window is the minimum size. could someone tell me why? and when it does work with ok size none of my bindings and images are there if.

1 个答案:

答案 0 :(得分:0)

原因在于这一行:

label.grid(row=5,)

这会导致父窗口(在本例中为画布)缩小以适合标签。

有许多解决方案,但这一切都取决于您期望的行为,这在您的问题中并不明确。一般来说,您不应在作为画布子级的窗口小部件上调用gridpack。通常,您使用画布的create_window方法将小部件放置在画布中。

还有其他解决方案,但正确的解决方案取决于您打算如何使用画布和标签。