tkinter窗口在命令行执行不出现的问题

import tkinter as tk
import random

windows=tk.Tk()
canvas = tk.Canvas(windows,width=500,height=500)
canvas.pack()

def random_rectangle(width,height,fill_color):
    x1= random.randrange(width)
    y1= random.randrange(height)
    x2= x1+random.randrange(width)
    y2= y1+random.randrange(height)
    canvas.create_rectangle(x1,y1,x2,y2,fill=fill_color)

for x in range(0,100):
    random_rectangle(400,400,'#eb5699')

windows.mainloop()

关键是最后一句:windows.mainloop()要加上去

你可能感兴趣的:(Python,Python错误)