简体   繁体   English

Python Tkinter调整窗口大小和Canvas问题

[英]Python Tkinter resizing window and Canvas issues

Hi i have this simple code which creates a tkinter window, resizes it and draws a line. 嗨,我有这个简单的代码,它创建一个tkinter窗口,调整它的大小并画一条线。 Why this line is being drawn almost in the center when it should start at the top left corner? 为什么该线应该从左上角开始在几乎中心位置绘制? (See the photo attached) (见附图)

import tkinter
# window size
window_size = 20 * 20
root = tkinter.Tk()
root.geometry('{}x{}'.format(window_size * 2, window_size))
root.resizable(width=False, height=False)
canvas = tkinter.Canvas(root)
canvas.pack()
canvas.create_line(0, 0, 100, 100, fill='red', width=10)
root.mainloop()

在此处输入图片说明

You need that canvas would fill the window: (canvas.pack(fill='both')) 您需要画布可以填充窗口:(canvas.pack(fill ='both'))

The complete code for canvas to take whole window space: 画布占用整个窗口空间的完整代码:

canvas.pack(side="top", fill="both", expand=True)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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