我正在用Python创建一个待办事项列表,我必须在开始时安排3个元素。其中包括一个笔记本,以便翻阅笔记和待办事项。其他的只是带有图像的标签。这是代码。我的问题是,我不确定该如何将这些图像放到网格上。位于第1行第0列的笔记本非常大,会导致第2列一直向右移动,从而无法将两个项目放在第1行的两列中,并彼此靠近。下面是代码
from tkinter import *
import datetime
from tkinter import ttk
import tkinter as tk
from tkinter.scrolledtext import ScrolledText
root = Tk()
root.title("To - Do List")
root.geometry("1200x600")
root.configure(background = "white")
# Variable list:
content = ttk.Frame(root)
content.grid(column=0, row=0, sticky=(N, S, E, W))
Photo1= PhotoImage(file="Full Circle Image Icon Docs.png")
Photo2 = PhotoImage(file="To - Do List Label.png")
TasksList = ttk.Notebook()
Task1 = ttk.Frame(TasksList)
Task2 = ttk.Frame(TasksList)
TasksList.add(Task1, text = 'One')
TasksList.add(Task2, text = 'Two')
TasksList.grid(row=2, column=0, sticky=W)
root.columnconfigure(0, weight=0)
root.rowconfigure(0, weight=0)
Label(image=Photo1, bg="black", borderwidth=0, highlightthickness=0).grid(row=0, column=0, sticky=W)
Label(image=Photo2, borderwidth=0, highlightthickness=0).grid(row=0, column=1, sticky=W)
root.mainloop()
非常感谢您的帮助。谢谢大家
将轴网设为三列宽,然后将column weigth=1设置为第三列,使其随窗口一起展开。然后将标签放在第一列和第二列
然后让TasksList用:
columnspan=3
填充所有三列另外,我将TasksList放在第二行,让它的权重为1,以便与窗口一起展开。请参见此示例:
在row=0中,第三列(空)将展开以填充窗口。在row=1中,任务列表将展开以填充窗口。有关更多信息,请参见The Tkinter Grid Geometry Manager
相关问题 更多 >
编程相关推荐