我正在尝试使用Python Gtk3调整窗口大小,但我需要扩展Notebook对象以填充主窗口。 我怎么能让笔记本填满窗户的其余部分呢?
这是我的代码:
#!/usr/bin/python
# coding=utf-8
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk
class SearchDialog(Gtk.Dialog):
def __init__(self, parent):
Gtk.Dialog.__init__(self, "Something", parent,
Gtk.DialogFlags.MODAL, buttons=(
Gtk.STOCK_NEW, Gtk.ResponseType.OK,
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
self.set_default_size(400, 600)
box = self.get_content_area()
label = Gtk.Label("Insert text you want to search for:")
box.add(label)
# self.entry = Gtk.Entry()
# box.add(self.entry)
self.main_area = Gtk.Stack()
self.main_area.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT)
self.main_area.set_transition_duration(1000)
self.entry = Gtk.Entry()
self.main_area.add_titled(self.entry, "entry_name", "Entry Url")
self.labelS = Gtk.Label()
self.label_txt = """<big><i> label here</i></big>"""
self.labelS.set_markup(self.label_txt)
self.labelS.set_line_wrap(True)
self.main_area.add_titled(self.labelS, "label_name", "How Scan will Start")
self.our_stackSwitcher = Gtk.StackSwitcher()
self.our_stackSwitcher.set_stack(self.main_area)
box.add(self.our_stackSwitcher)
box.add(self.main_area)
self.show_all()
class MyWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Desktop app title")
self.set_default_size(1000, 648)
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
self.add(vbox)
Hbox1 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
vbox.add(Hbox1)
Hbox2 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
vbox.add(Hbox2)
Hbox3 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
vbox.add(Hbox3)
Hbox4 = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
vbox.add(Hbox4)
main_menu_bar = Gtk.MenuBar()
#################################################################################
#drop down the menu
file_menu1 = Gtk.Menu()
file_menu1_dropdown = Gtk.MenuItem("File")
#File menu Items
file_new = Gtk.MenuItem("New Scan")
file_save = Gtk.MenuItem("Save History")
file_exit = Gtk.MenuItem("Exit")
file_menu1_dropdown.set_submenu(file_menu1)
file_menu1.append(file_new)
file_new.connect("activate", self.Onclick_new)
file_menu1.append(file_save)
file_save.connect("activate", self.Onclick_save)
file_menu1.append(Gtk.SeparatorMenuItem())
file_menu1.append(file_exit)
file_exit.connect("activate",self.Onclick_exit)
#add the menu to the main menu bar
main_menu_bar.append(file_menu1_dropdown)
###################################################################################
#drop down the menu
file_menu2 = Gtk.Menu()
file_menu2_dropdown = Gtk.MenuItem("Scan")
#File menu Items
file_edit = Gtk.MenuItem("Edit")
file_cancel = Gtk.MenuItem("Cancel")
file_menu2_dropdown.set_submenu(file_menu2)
file_menu2.append(file_edit)
file_edit.connect("activate", self.Onclick_edit)
file_menu2.append(file_cancel)
file_cancel.connect("activate", self.Onclick_cancel)
#add the menu to the main menu bar
main_menu_bar.append(file_menu2_dropdown)
###################################################################################
#drop down the menu
file_menu3 = Gtk.Menu()
file_menu3_dropdown = Gtk.MenuItem("Help")
#File menu Items
file_mode = Gtk.MenuItem("Mode")
file_about = Gtk.MenuItem("About")
file_menu3_dropdown.set_submenu(file_menu3)
file_menu3.append(file_mode)
file_mode.connect("activate", self.Onclick_mode)
file_menu3.append(file_about)
file_about.connect("activate", self.Onclick_about)
#add the menu to the main menu bar
main_menu_bar.append(file_menu3_dropdown)
###################################################################################
## ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ##
Hbox1.pack_start(main_menu_bar , True, True, 0)
label1_Hbox2 = Gtk.Label(" i am label 1 of Horizental box 2")
Hbox2.pack_start(label1_Hbox2 , True, True, 0)
label2_Hbox2 = Gtk.Label(" i am label 2 of Horizental box 2")
Hbox2.pack_start(label2_Hbox2, True, True, 0)
self.notebook1 = Gtk.Notebook()
Hbox3.pack_start(self.notebook1, True, True, 0)
self.notebook2 = Gtk.Notebook()
Hbox3.pack_start(self.notebook2, True, True, 0)
##################################################################################################
self.page1 = Gtk.Box()
self.page1.set_border_width(3)
self.label = Gtk.Label('label Number 1-------')
self.page1.add(self.label)
self.label2 = Gtk.Label('label Number 2 should appear in next line')
self.page1.add(self.label2)
self.notebook1.append_page(self.page1, Gtk.Label('Tab Pane 1 panel 1'))
###################################################################################################
self.page1 = Gtk.Box()
self.notebook2.append_page(self.page1, Gtk.Label('Tab Pane 1 panel 2'))
self.page2 = Gtk.Box()
self.notebook2.append_page(self.page2, Gtk.Label('Tab Pane 2 panel 2'))
def Onclick_new(self, widget):
dialog = SearchDialog(self)
response = dialog.run()
if response == Gtk.ResponseType.OK:
self.label.set_text(dialog.entry.get_text())
dialog.destroy()
def Onclick_save(self, widget):
print("Save clicked")
def Onclick_exit(self, widget):
print("exit clicked")
Gtk.main_quit()
def Onclick_edit(self, widget):
print("Edit clicked")
def Onclick_cancel(self, widget):
print("Cancel clicked")
def Onclick_mode(self, widget):
print("Mode of use clicked")
def Onclick_about(self, widget):
print("About clicked")
#cssProvider = Gtk.CssProvider()
#cssProvider.load_from_path('gtkStyledButtonTest.css')
#screen = Gdk.Screen.get_default()
#styleContext = Gtk.StyleContext()
#styleContext.add_provider_for_screen(screen, cssProvider,
# Gtk.STYLE_PROVIDER_PRIORITY_USER)
win = MyWindow()
win.connect("delete-event", Gtk.main_quit)
win.show_all()
Gtk.main()