多标签框架,tkinter GUI与特定的行和列不匹配

时间:2016-07-09 13:47:22

标签: python user-interface tkinter

我在程序的第1列中创建2帧,第一个是ok,我使用sticky = N,它在顶部正确定位,但对于下一帧,它不会出现在我的程序的底部,

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

这是我如何定义第一帧:

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)

我认为可以设置grid_rowconfigure和grid_columnconfigure但不知道如何在我的代码中修复它,问候。

完整编码:

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()

:这是一个屏幕截图,显示“案例建议”如何无法出现在“期间选择”下方 screenshot

1 个答案:

答案 0 :(得分:0)

框架正好出现在您告诉它出现的位置。你提出了案例建议......"在第8行,这意味着它必须出现在第0行下面。但是,第0行非常高,这意味着它下方的任何内容都将离开屏幕的可见部分,因为您强制屏幕为特定大小并且不要在屏幕上显示。允许它重新调整大小。

如果我理解你想要的东西(&#34;案例建议......&#34;紧接着#34;期间选择&#34;),你需要做两件事来快速和肮脏的修复:< / p>

  1. 移动&#34;案例建议......&#34;到第1行,
  2. 制作&#34;用户活动历史记录&#34;跨越两行
  3. 例如:

    none