画布行未显示在屏幕上

时间:2019-11-11 15:46:08

标签: python tkinter tkinter-canvas

因此,我创建了该行,并弹出了窗口,但该行未显示

我实际上已经尝试了一切,到目前为止,我真的不知道该怎么办。是否在我初始化画布小部件本身的部分周围?

import tkinter as ttk
from datetime import datetime
from PIL import ImageTk, Image
from weather import rawdata
import time

root = ttk.Tk()
root.geometry("800x600")
root.title("New window")

# -------------get date information---------- #

now = datetime.now()
dt_string = now.strftime("%d/%m/%y")

# grab image

imagepath = "D:\\Programing\\BG_sky.jpg"
background_picture = ImageTk.PhotoImage(Image.open(imagepath))
backgroundimage = ttk.Label(root, image=background_picture)
backgroundimage.pack(side="bottom", fill="both", expand="yes")


# ------------Make loop for weatherdata------------- #

# ------------build window ------------------#

date = ttk.Label(root, text=dt_string, font=('helvetica', 15))
date.place(x=100, y=300)

weather = ttk.Label(root, text=(rawdata), font=('helvetica', 15))
weather.place(x=190, y=300)

canvas = ttk.Canvas(root)

line = canvas.create_line(220, 350, 220, 100, fill="black", dash=(4, 4))


root.mainloop()

1 个答案:

答案 0 :(得分:0)

问题不在于显示的行。问题是您尚未将画布添加到窗口中。您需要使用packgridplace将画布添加到窗口中。