Tkinter:不能在内部使用几何图形管理器网格.!frame2,该frame2已经具有由pack管理的从机



这是我第一次使用tkinter,我已经对packgrid进行了一些研究。如何修复此代码,使packgrid组件不会相互缠绕?

我想使用网格作为我的复选框,这样16个复选框就会显示在与它们对应的单词旁边的一列中。我能用背包做这个吗?

# tkinter will help us with the GUI
import tkinter as tk
from tkinter import filedialog, Text
import os

def data():
categoriesArray = ["16 words here"] 
for i in range(16):
checkbox = tk.Checkbutton(buttonFrame, bg="white")
checkbox.grid(row=i, column=0, sticky="w")
tk.Label(canvasFrame, text=categoriesArray[i]).grid(row=i, column=1, sticky="ew")
# Define the scrolling function for the scrollbar
def scrollFunction(event):
canvas.configure(scrollregion=canvas.bbox("all"), width=200, height=500)
# The root holds the whole app structure. Always attach to root.
root = tk.Tk()
# These two lines literally make the rectangular structure of the app.
canvas = tk.Canvas(root, height = 500, width= 1300, bg="#00008B")
canvas.pack()
# These two lines make the white screen you see on the left of the buttons.
frame = tk.Frame(root, bg="white")
frame.place(relwidth=0.8, relheight=0.8, relx=0.03, rely=0.1)
# This is the frame for the buttons on the right
buttonFrame = tk.Frame(root, bg="white")
buttonFrame.place(relwidth=0.13, relheight=0.8, relx=0.85, rely=0.1)
# You need a canvas to define a scrollbar within the app.
# Resource: https://stackoverflow.com/questions/16188420/tkinter-scrollbar-for-frame
canvas=tk.Canvas(buttonFrame)
canvasFrame=tk.Frame(canvas)
scrollbar=tk.Scrollbar(buttonFrame, orient="vertical", command=canvas.yview)
canvas.configure(yscrollcommand=scrollbar.set)
scrollbar.pack(side="right", fill="y")
canvas.pack(side="left")
canvas.create_window((36,0), window=canvasFrame, anchor='nw')
canvasFrame.bind("<Configure>", scrollFunction)
# Call the data for the categories to show on the right
data()
# This runs the mainframe to work
root.mainloop()

请让我知道我能做些什么让我的问题变得更好。

我看过但弄糊涂的地方:修复这个代码';不能在内部使用几何图形管理器网格。其已经具有由pack';

我修复了它。checkbox = tk.Checkbutton(buttonFrame, bg="white")应该有canvasFrame而不是buttonFrame

最新更新