简体   繁体   中英

Multiple Label Frame, tkinter GUI did not match the specific row and column

I create 2 frame in column 1 in my program, the first one is ok, i use sticky = N,it position properly at the top, but for the next frame, it does not appear at the bottom of my program, here is the

[ http://i.stack.imgur.com/01sSf.jpg]

here is how i define the first frame:

def DateSelection(self):
    self.SelectDateFrame = LabelFrame(self,text="Period Selection",height= 215,width =260)
    self.SelectDateFrame.grid(row= 0, column=1,padx=2,sticky=N)
    self.SelectDateFrame.grid_propagate(0)

    instructionLabel=Label(self.SelectDateFrame,text="Enter a date or use the select date button.")
    instructionLabel.grid(row =1,column=1)

    startDateLabel=Label(self.SelectDateFrame,text="Start Date:")
    startDateLabel.grid(row =2,column=1,sticky=W)

    startDate_ent =Entry(self.SelectDateFrame,width=40)
    startDate_ent.grid(row =3, column =1,padx=6,pady=6)

    endDateLabel=Label(self.SelectDateFrame,text="End Date:")
    endDateLabel.grid(row =5,column=1,sticky=W)

    endDate_ent =Entry(self.SelectDateFrame,width=40)
    endDate_ent.grid(row =6, column =1,padx=6,pady=6)

    # Create the Select start date and Select end date button for UAH
    StartDatebtn = Button(self.SelectDateFrame, text="Select Start Date", command=printMessage,height =1, width =12)
    StartDatebtn.grid(row=4,column=1)

    EndDatebtn = Button(self.SelectDateFrame, text="Select End Date", command=printMessage,height =1, width =12)
    EndDatebtn.grid(row=7,column= 1)

This is the second frame code which did not appear below the first frame in my program:

def UASuggestion(self):
    self.SuggestUAFrame = LabelFrame(self,text="Case Suggestion for UA",height= 220,width =220)
    self.SuggestUAFrame.grid(row=8, column=1,padx=2,pady=2,sticky=N,)
    self.SuggestUAFrame.grid_propagate(0)

I think can set the grid_rowconfigure and grid_columnconfigure but not sure how this can fix in my code,Regards.

Complete coding:

from tkinter import *

class ConfigureUAinterface(Frame):
    def __init__(self, root):
        root.minsize(width=700, height=500)
        root.maxsize(width=700, height=500)
        Frame.__init__(self, root)
        Grid.config(self)
        self.ConfigurationUA()
        self.DateSelection()
        self.UASuggestion()

    def ConfigurationUA(self):
        self.UAHFrame = LabelFrame(self,text="User Activity History",height= 495,width =200)
        self.UAHFrame.grid(row= 0, column=0,padx=2)
        self.UAHFrame.grid_propagate(0)

    def setUACheck():
        Jumplistvar.set(True)
        USBDevicevar.set(True)
        Prefetchvar.set(True)
        UserAssistvar.set(True)
        WindowsSearchvar.set(True)
        GoogleSearchHistoryvar.set(True)
        NetworkProfilevar.set(True)
        DownloadHistoryvar.set(True)
        InstallProgramCheckvar.set(True)
        MRUvar.set(True)
        ShellBagvar.set(True)
        BrowserHistoryvar.set(True)
        BrowserFormHistoryvar.set(True)

    def setUAUNCheck():
        Jumplistvar.set(False)
        USBDevicevar.set(False)
        Prefetchvar.set(False)
        UserAssistvar.set(False)
        WindowsSearchvar.set(False)
        GoogleSearchHistoryvar.set(False)
        NetworkProfilevar.set(False)
        DownloadHistoryvar.set(False)
        InstallProgramCheckvar.set(False)
        MRUvar.set(False)
        ShellBagvar.set(False)
        BrowserHistoryvar.set(False)
        BrowserFormHistoryvar.set(False)

    #Set the UAH variable as a booloean
    Jumplistvar = BooleanVar()
    Jumplistvar.set(False)
    JumplistCheck = Checkbutton(self.UAHFrame,text="Jumplist", variable=Jumplistvar)
    JumplistCheck.grid(row=1,column=0,sticky=W)

    USBDevicevar = BooleanVar()
    USBDevicevar.set(False)
    USBDeviceCheck = Checkbutton(self.UAHFrame,text="USB Device", variable=USBDevicevar)
    USBDeviceCheck.grid(row=2,column=0,sticky=W)

    Prefetchvar = BooleanVar()
    Prefetchvar.set(False)
    PrefetchCheck = Checkbutton(self.UAHFrame,text="Prefetch", variable=Prefetchvar)
    PrefetchCheck.grid(row=3,column=0,sticky=W)

    UserAssistvar = BooleanVar()
    UserAssistvar.set(False)
    UserAssistCheck = Checkbutton(self.UAHFrame,text="User Assist", variable=UserAssistvar)
    UserAssistCheck.grid(row=4,column=0,sticky=W)

    WindowsSearchvar = BooleanVar()
    WindowsSearchvar.set(False)
    WindowsSearchCheck = Checkbutton(self.UAHFrame,text="Windows Search", variable=WindowsSearchvar)
    WindowsSearchCheck.grid(row=5,column=0,sticky=W)

    GoogleSearchHistoryvar = BooleanVar()
    GoogleSearchHistoryvar.set(False)
    GoogleSearchHistoryCheck = Checkbutton(self.UAHFrame,text="Google Search History",
                                           variable=GoogleSearchHistoryvar)
    GoogleSearchHistoryCheck.grid(row=6,column=0,sticky=W)

    NetworkProfilevar = BooleanVar()
    NetworkProfilevar.set(False)
    NetworkProfileCheck = Checkbutton(self.UAHFrame,text="Network Profile", variable=NetworkProfilevar)
    NetworkProfileCheck.grid(row=7,column=0,sticky=W)

    DownloadHistoryvar = BooleanVar()
    DownloadHistoryvar.set(False)
    DownloadHistoryCheck = Checkbutton(self.UAHFrame,text="Download History", variable=DownloadHistoryvar)
    DownloadHistoryCheck.grid(row=8,column=0,sticky=W)

    InstallProgramCheckvar = BooleanVar()
    InstallProgramCheckvar.set(False)
    InstallProgramCheck = Checkbutton(self.UAHFrame,text="Install Programs", variable=InstallProgramCheckvar)
    InstallProgramCheck.grid(row=9,column=0,sticky=W)

    MRUvar = BooleanVar()
    MRUvar.set(False)
    MRUCheck = Checkbutton(self.UAHFrame,text="Most Recently Used(MRU) List", variable=MRUvar)
    MRUCheck.grid(row=10,column=0,sticky=W)

    ShellBagvar = BooleanVar()
    ShellBagvar.set(False)
    ShellBagCheck = Checkbutton(self.UAHFrame,text="ShellBag", variable=ShellBagvar)
    ShellBagCheck.grid(row=11,column=0,sticky=W)

    BrowserHistoryvar = BooleanVar()
    BrowserHistoryvar.set(False)
    BrowserHistoryCheck = Checkbutton(self.UAHFrame,text="Browser History", variable=BrowserHistoryvar)
    BrowserHistoryCheck.grid(row=12,column=0,sticky=W)

    BrowserFormHistoryvar = BooleanVar()
    BrowserFormHistoryvar.set(False)
    BrowserFormHistoryCheck = Checkbutton(self.UAHFrame,text="Browser Form History", variable=BrowserFormHistoryvar)
    BrowserFormHistoryCheck.grid(row=13,column=0,sticky=W)

    # Create the check and uncheck button for UAH
    UACheckbtn = Button(self.UAHFrame, text="Check all UA", command=setUACheck,height =2, width =21)
    UACheckbtn.grid(row=14,column= 0,pady=6,padx=18)

    UAunCheckbtn = Button(self.UAHFrame, text="Uncheck all UA", command=setUAUNCheck,height =2, width =21)
    UAunCheckbtn.grid(row=15,column= 0,pady=6,padx=18)

    def DateSelection(self):
        self.SelectDateFrame = LabelFrame(self,text="Period Selection",height= 215,width =260)
        self.SelectDateFrame.grid(row= 0, column=1,padx=2,sticky=N)
        self.SelectDateFrame.grid_propagate(0)

        instructionLabel=Label(self.SelectDateFrame,text="Enter a date or use the select date button.")
        instructionLabel.grid(row =1,column=1)

        startDateLabel=Label(self.SelectDateFrame,text="Start Date:")
        startDateLabel.grid(row =2,column=1,sticky=W)

        startDate_ent =Entry(self.SelectDateFrame,width=40)
        startDate_ent.grid(row =3, column =1,padx=6,pady=6)

        endDateLabel=Label(self.SelectDateFrame,text="End Date:")
        endDateLabel.grid(row =5,column=1,sticky=W)

        endDate_ent =Entry(self.SelectDateFrame,width=40)
        endDate_ent.grid(row =6, column =1,padx=6,pady=6)

        # Create the Select start date and Select end date button for UAH
        StartDatebtn = Button(self.SelectDateFrame, text="Select Start Date", command=printMessage,height =1, width =12)
        StartDatebtn.grid(row=4,column=1)

        EndDatebtn = Button(self.SelectDateFrame, text="Select End Date", command=printMessage,height =1, width =12)
        EndDatebtn.grid(row=7,column= 1)

    def UASuggestion(self):
        self.SuggestUAFrame = LabelFrame(self,text="Case Suggestion for UA",height= 220,width =220)
        self.SuggestUAFrame.grid(row=8, column=1,padx=2,pady=2,sticky=N,)
        self.SuggestUAFrame.grid_propagate(0)

def printMessage():
    print("Wow this actually worked!")

root = Tk()
root.title("UA Configuration")
cuai= ConfigureUAinterface(root)
root.mainloop()

: This is a screenshot showing how "Case Suggestion" fails to appear right below "Period Selection" screenshot

The frame is appearing exactly where you tell it to appear. You placed "Case suggestion ..." in row 8, which means it must appear below row 0. However, row 0 is very tall, which means anything below it will be off the visible part of the screen since you forced the screen to be a specific size and don't allow it to be re-sized.

If I understand what you want ("Case suggestion..." immediately below "Period Selection"), you need to do two things for a quick and dirty fix:

  1. move "Case suggestion..." to row 1, and
  2. make "User Activity History" span two rows

For example:

self.UAHFrame.grid(row= 0, column=0, rowspan=2, ...)
...
self.SuggestUAFrame.grid(row=1, column=1,...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM