Python “错误”;无法在内部使用几何图形管理器包。它已经有了由网格管理的从机;

Python “错误”;无法在内部使用几何图形管理器包。它已经有了由网格管理的从机;,python,tkinter,Python,Tkinter,因此,我尝试允许用户上传一个标志的图像文件,然后将其打包到框架中。但是,我收到以下错误消息无法在内部使用几何体管理器包。它已经有了由网格管理的从属程序,我不明白为什么会发生这种情况,因为我在同一个框架中有大量其他小部件使用.pack。我曾尝试在帧上使用.pack,但我遇到了另一个问题,我的程序刚刚崩溃。 这是代码 # Imports from tkinter import * # Tkinter is a GUI toolkit used for Python. This toolkit all

因此,我尝试允许用户上传一个标志的图像文件,然后将其打包到框架中。但是,我收到以下错误消息
无法在内部使用几何体管理器包。它已经有了由网格管理的从属程序,我不明白为什么会发生这种情况,因为我在同一个框架中有大量其他小部件使用
.pack
。我曾尝试在帧上使用
.pack
,但我遇到了另一个问题,我的程序刚刚崩溃。 这是代码

# Imports
from tkinter import * # Tkinter is a GUI toolkit used for Python. This toolkit allows me to create the window and many of the UI options
import Pmw # Pmw stands for 'Python mega widgets'. I imported this primarily for tooltips so the user knows what everything means
from PIL import ImageTk,Image
from tkinter import filedialog

# Windows
root = Tk() # Root is the main window where I will be putting everything
root.title('Nation Creator') # The title is the text at the top of every window
root.state('zoomed') # This makes the window go full screen
#Fonts
titlefont = ("Aldrich", 48)
subtitlefont = ("Aldrich", 22)
font = ("Times New Roman", 14)

#lists
hosl = ["Elected Monarch", "Hereditary Monarch", "Elected President", "Oligarchy"] #These are the four types of heads of state.
# Functions

#This is so that the user can scroll thru the next frame.
def nextframe(frame):
    frame.tkraise()

# Making the frames
def frameMaker():
    frameName = Frame(root)
    frameName.grid(row=0,column=0,sticky='nsew')
    return frameName

# This is what makes my Titles
def titleMaker(titleText, descriptionText, frame):
    title = Label(frame, text = titleText)
    title.configure(font=(titlefont))
    title.pack()
    description = Label(frame, text = descriptionText)
    description.configure(font=(subtitlefont))
    description.pack()
    return title, description

# Here I am making my spaces. It gives a better asthetic look.
def spaceMaker(spaceName, frame):
    spaceName = Label(frame, text="")
    spaceName.pack()
    return spaceName

#This opens a file browser so you can select your flag
def flagOpener():
        global flagIMG
        global flagLabel
        flagPath = filedialog.askopenfilename(initialdir="/", title="Select an Image File", filetypes=(("Png Files", "*.png"), ("Jpeg Files", "*.jpg; *.jpeg"), ("All Files", "*.*")))
        flagIMG = ImageTk.PhotoImage(Image.open(flagPath))
        flagLabel = Label(image=flagIMG)
        flagLabel.pack()
        return flagIMG, flagLabel
#######################################################
#######################FRAMES##########################
#######################################################

# These two commands allow the different frames to work
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
# There will be 4 different frames.
titleframe = frameMaker()
politicalframe = frameMaker()
econframe = frameMaker()
miscframe = frameMaker()

for frame in (titleframe, politicalframe, econframe, miscframe):
    frame.grid(row=0,column=0,sticky='nsew')

nextframe(titleframe)
# Section Headings
# These will be the headings for the sections.
# There will be 4 sections; Title Section, Political, Economic, and Micellanious 

titleMaker("Nation Creator","Version 1.0",titleframe)
startbutton = Button(titleframe, text = "Begin", command=lambda:nextframe(politicalframe))
startbutton.pack()

#Political Section

titleMaker("Political Section","This is where your nation's name, flag, territory, \nand political and personal freedoms are entered.",politicalframe)

spaceMaker("pOne", politicalframe)

nationNamePrompt = Label(politicalframe, text = "Enter your nation's name:")
nationNamePrompt.configure(font = (font))
nationNamePrompt.pack()
nationNameInput = Entry(politicalframe)
nationNameInput.configure(font=(font))
nationNameInput.pack()

spaceMaker("pTwo", politicalframe)

flagSelect = Button(politicalframe, text = "Select Flag", command=flagOpener)
flagSelect.pack()


spaceMaker("pThree", politicalframe)

territoryPrompt = Label(politicalframe, text = "List Your Territory")
territoryPrompt.configure(font=(font))
territoryPrompt.pack()
territoryButton = Entry(politicalframe)
territoryButton.configure(font=(font))
territoryButton.pack()

spaceMaker("pFour", politicalframe)

headOfStateVar = StringVar(politicalframe)
headOfStateVar.set("Select Head of State")
headOfStateType = OptionMenu(politicalframe, headOfStateVar, *hosl)
headOfStateType.pack()

spaceMaker("pFive", politicalframe)

headOfStateNamePrompt = Label(politicalframe, text = "What is the name of your head of state?")
headOfStateNamePrompt.configure(font=(font))
headOfStateNamePrompt.pack()
headOfStateName = Entry(politicalframe)
headOfStateName.configure(font=(font))
headOfStateName.pack()

spaceMaker("pSix", politicalframe)

polcontbutton = Button(politicalframe, text = "Next", command=lambda:nextframe(econframe))
polcontbutton.pack()
#Economic Section 
titleMaker("Economic Section","This is where your economic freedoms and control are entered.",econframe)

econbackbutton = Button(econframe, text = "Back", command=lambda:nextframe(politicalframe))
econbackbutton.pack()

# Making sure the window will stay up
root.mainloop()
flagOpener()函数中:

def flagOpener():
全球旗帜
全球旗标
flagPath=filedialog.askopenfilename(initialdir=“/”,title=“选择一个图像文件”,文件类型=((“Png文件”、“*.Png”)、(“Jpeg文件”、“*.jpg;*.Jpeg”)、(“所有文件”、“*.Jpeg”))
flagIMG=ImageTk.PhotoImage(Image.open(flagPath))
flagLabel=Label(图像=flagIMG)
flagLabel.pack()
返回flagIMG,flagLabel
您没有为
标记标签
指定父项。Tkinter使用了master的默认选项,即
root
,但您在此处使用了root的
网格
管理器:

def frameMaker():
frameName=框架(根)
frameName.grid(行=0,列=0,sticky='nsew')
返回帧名
在这里:

titleframe=frameMaker()
politicalframe=frameMaker()
econframe=frameMaker()
miscframe=frameMaker()
对于帧输入(标题帧、政治帧、经济帧、杂项帧):
frame.grid(行=0,列=0,sticky='nsew')
Tkinter不允许对同一帧/窗口使用不同的管理器。还有,为什么要为:
(titleframe、politicalframe、econframe、miscsframe)
调用两次
.grid
方法?进入
frameMaker
功能后,再次进入for循环。您不应该这样做。

flagOpener()函数中:

def flagOpener():
全球旗帜
全球旗标
flagPath=filedialog.askopenfilename(initialdir=“/”,title=“选择一个图像文件”,文件类型=((“Png文件”、“*.Png”)、(“Jpeg文件”、“*.jpg;*.Jpeg”)、(“所有文件”、“*.Jpeg”))
flagIMG=ImageTk.PhotoImage(Image.open(flagPath))
flagLabel=Label(图像=flagIMG)
flagLabel.pack()
返回flagIMG,flagLabel
您没有为
标记标签
指定父项。Tkinter使用了master的默认选项,即
root
,但您在此处使用了root的
网格
管理器:

def frameMaker():
frameName=框架(根)
frameName.grid(行=0,列=0,sticky='nsew')
返回帧名
在这里:

titleframe=frameMaker()
politicalframe=frameMaker()
econframe=frameMaker()
miscframe=frameMaker()
对于帧输入(标题帧、政治帧、经济帧、杂项帧):
frame.grid(行=0,列=0,sticky='nsew')

Tkinter不允许对同一帧/窗口使用不同的管理器。还有,为什么要为:
(titleframe、politicalframe、econframe、miscsframe)
调用两次
.grid
方法?进入
frameMaker
功能后,再次进入for循环。你不应该这样做。

你知道在
flagOpener()
函数中你定义了
tkinter.Label
而没有主控吗?你知道在
flagOpener()
函数中你定义了
tkinter.Label
而没有主控吗?我真不敢相信我漏掉了!非常感谢。我真不敢相信我竟然漏掉了!非常感谢。