我可以在 canvas 行(tkinter)中设置标签位置吗?
Can I set the label position in the canvas line (tkinter)?
enter image description here
我想花时间 (00:00) 到 canvas 行(矩形)。
我想我应该将标签的位置设置为正确的方式,但它不起作用。
from tkinter import *
import tkinter as tk
root = tk.Tk()
canvas = Canvas(width=600, height=180, bg='white')
canvas.pack(expand=YES, fill=BOTH)
root.geometry("605x182")
root.title("display")
#root.resizable(False, False)
status = Label(canvas, text='Status : ', fg='white', bg='#213058')
status.pack(anchor="w",padx=3, pady=3)
line = canvas.create_line(3, 0, 3, 90, fill="#213058", width=5)
line = canvas.create_line(3, 3, 600, 3, fill="#213058", width=5)
line = canvas.create_line(600, 0, 600, 90, fill="#213058", width=5)
line = canvas.create_line(2, 90, 600, 90, fill="#213058", width=5)
time = Label(canvas, text='Time : ', fg='white', bg='#213058')
time.pack(anchor="w",padx= 229,pady=61)
line = canvas.create_line(230, 90, 230, 177, fill="#213058", width=5)
line = canvas.create_line(228, 177, 603, 177, fill="#213058", width=5)
line = canvas.create_line(600, 177, 600, 90, fill="#213058", width=5)
showtime = Label(canvas, text='00:00', fg='white', bg='#213058')
showtime.pack(anchor="w",padx= 0,pady=0)
mainloop()
这是我的代码。
我不知道如何修复它。请帮助我。
非常感谢。
您可以使用 create_window
添加标签小部件,或使用 create_text
添加文本而不创建额外的标签小部件。然后你可以把它放在任何你想要的地方。
enter image description here
我想花时间 (00:00) 到 canvas 行(矩形)。 我想我应该将标签的位置设置为正确的方式,但它不起作用。
from tkinter import *
import tkinter as tk
root = tk.Tk()
canvas = Canvas(width=600, height=180, bg='white')
canvas.pack(expand=YES, fill=BOTH)
root.geometry("605x182")
root.title("display")
#root.resizable(False, False)
status = Label(canvas, text='Status : ', fg='white', bg='#213058')
status.pack(anchor="w",padx=3, pady=3)
line = canvas.create_line(3, 0, 3, 90, fill="#213058", width=5)
line = canvas.create_line(3, 3, 600, 3, fill="#213058", width=5)
line = canvas.create_line(600, 0, 600, 90, fill="#213058", width=5)
line = canvas.create_line(2, 90, 600, 90, fill="#213058", width=5)
time = Label(canvas, text='Time : ', fg='white', bg='#213058')
time.pack(anchor="w",padx= 229,pady=61)
line = canvas.create_line(230, 90, 230, 177, fill="#213058", width=5)
line = canvas.create_line(228, 177, 603, 177, fill="#213058", width=5)
line = canvas.create_line(600, 177, 600, 90, fill="#213058", width=5)
showtime = Label(canvas, text='00:00', fg='white', bg='#213058')
showtime.pack(anchor="w",padx= 0,pady=0)
mainloop()
这是我的代码。
我不知道如何修复它。请帮助我。
非常感谢。
您可以使用 create_window
添加标签小部件,或使用 create_text
添加文本而不创建额外的标签小部件。然后你可以把它放在任何你想要的地方。