我在程序的第 1 列中创建 2 帧,第一个还可以,我使用 sticky = N,它在顶部正确定位,但对于下一帧,它没有出现在我的程序底部,这里是
[https://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()
:这是显示"案例建议"如何无法显示在"期间选择"正下方的屏幕截图截图
框架正好出现在您告诉它出现的位置。您放置了"案例建议..."在第 8 行中,这意味着它必须显示在第 0 行下方。但是,第 0 行非常高,这意味着它下面的任何内容都将不在屏幕的可见部分,因为您强制屏幕为特定大小并且不允许重新调整其大小。
如果我明白你想要什么("案例建议..."紧靠"周期选择"),您需要做两件事才能快速而肮脏地修复:
- 移动"案例建议..."到第 1 行,以及
- 使"用户活动历史记录"跨越两行
例如:
self.UAHFrame.grid(row= 0, column=0, rowspan=2, ...)
...
self.SuggestUAFrame.grid(row=1, column=1,...)