我的主窗口启动一个带有子框架(用于浏览/选择目录)的顶级窗口以及底部的“加载”和“添加目录”按钮。“添加目录”按钮删除所有目录条目子框架(但保留按钮),检查没有输入的重复目录或空字符串,并为有效条目重新创建子框架并创建另一个留空。
问题是当我单击“添加目录”按钮时,按钮最终位于顶部。有没有办法将按钮固定到窗口底部?
在主类中:
def add_directory
dir_window = TkToplevel.new(@root) {title 'Directories'}
dir_frame = Tk::Tile::Frame.new(dir_window) {padding "3 3 12 12"}.grid(:sticky => 'nsew')
DirectoryFrame.show(dir_frame)
loadDirectoriesButtonClicked = proc {load_files}
Tk::Tile::Button.new(dir_frame) {text 'Load directories'; command loadDirectoriesButtonClicked}.grid(:column=>0, :sticky=>'s')
addDirButtonClicked = proc {DirectoryFrame.show(dir_frame)}
Tk::Tile::Button.new(dir_frame) {text '+'; width 2; command addDirButtonClicked}.grid(:column=>1, :sticky=>'sw')
end
在目录框架类中:
class DirectoryFrame < Tk::Tile::Frame
@@directory_frames = []
@@directories = []
def self.show(parent_frame)
if !(@@directory_frames.nil? || @@directory_frames.empty?)
directories
remove_frames(parent_frame)
end
@@directories.delete("")
if !(@@directories.nil? || @@directories.empty?)
@@directories.each do |dir|
dir_frame = DirectoryFrame.new(parent_frame)
dir_frame.directory = dir
@@directory_frames << dir_frame
end
end
@@directory_frames << DirectoryFrame.new(parent_frame)
refresh
end
def self.refresh
@@directory_frames.each_with_index do |dir_frame, index|
dir_frame.grid(:row=>index, :sticky=>'ew')
end
end