我有这个程序,并且,尽管我尝试我不能使元素扩展占据为应用程序的轮胎尺寸定义的区域。
代码:
import smtpClass
import xmlHostes
import pygtk
pygtk.require('2.0')
import gtk
class Base:
def get_main_menu(self, window):
accel_group = gtk.AccelGroup()
item_factory = gtk.ItemFactory(gtk.MenuBar, "<main>", accel_group)
item_factory.create_items(self.menu_items)
window.add_accel_group(accel_group)
self.item_factory = item_factory
return item_factory.get_widget("<main>")
def __init__(self):
## MENU CONTENT
self.menu_items = (# MENU TREE # CONTROL KEY # FUNCTION
( "/_File", None, None, 0, "<Branch>" ),
( "/File/_Setings", "<control>S", None, 0, None ),
( "/File/Quit", "<control>Q", gtk.main_quit, 0, None ),
( "/_Help", None, None, 0, "<LastBranch>" ),
( "/_Help/About", None, None, 0, None ),
)
# WINDOW WIDGET
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_title("pyAnonMail")
self.window.set_size_request(500, 500)
# CONTEINER DATA
main_vbox = gtk.VBox(False, 5)
#main_vbox.set_border_width(1)
self.window.add(main_vbox)
main_vbox.show()
self.contentTable = gtk.Table(1, 3, True)
main_vbox.pack_start(self.contentTable, True, True, 10)
# ADD MENU TO CONTEINER
self.menubar = self.get_main_menu(self.window)
main_vbox.add(self.menubar)
self.menubar.show()
# FRAME 1 ##########################################################
self.frame1 = gtk.Frame()
self.contentTable.attach(self.frame1, 0, 1, 0, 1,
gtk.FILL, gtk.EXPAND | gtk.SHRINK | gtk.FILL, 0, 0)
self.frame1.set_label_align(0.0, 0.0)
self.frame1.set_label("Enter message data")
self.frame1.set_shadow_type(gtk.SHADOW_ETCHED_OUT)
self.frame1.show()
# DATA TABLE
dataTable = gtk.Table(2, 6, False)
self.frame1.add(dataTable)
dataTable.show()
senderNameFrame = gtk.Label("Sender Name:")
dataTable.attach(senderNameFrame, 0, 1, 0, 1,
gtk.FILL, gtk.EXPAND | gtk.SHRINK | gtk.FILL, 0, 0)
senderNameFrame.show()
senderNameEntry = gtk.Entry()
dataTable.attach(senderNameEntry, 0, 1, 1, 2,
gtk.FILL, gtk.EXPAND | gtk.SHRINK | gtk.FILL, 0, 0)
senderNameEntry.show()
senderEmailFrame = gtk.Label("Sender Email:")
dataTable.attach(senderEmailFrame, 1, 2, 0, 1,
gtk.FILL, gtk.EXPAND | gtk.SHRINK | gtk.FILL, 0, 0)
senderEmailFrame.show()
senderEmailEntry = gtk.Entry()
dataTable.attach(senderEmailEntry, 1, 2, 1, 2,
gtk.FILL, gtk.EXPAND | gtk.SHRINK | gtk.FILL, 0, 0)
senderEmailEntry.show()
recipientNameFrame = gtk.Label("Recipient Name:")
dataTable.attach(recipientNameFrame, 0, 1, 2, 3,
gtk.FILL, gtk.EXPAND | gtk.SHRINK | gtk.FILL, 0, 0)
recipientNameFrame.show()
recipientNameEntry = gtk.Entry()
dataTable.attach(recipientNameEntry, 0, 1, 3, 4,
gtk.FILL, gtk.EXPAND | gtk.SHRINK | gtk.FILL, 0, 0)
recipientNameEntry.show()
recipientEmailFrame = gtk.Label("Recipient Email:")
dataTable.attach(recipientEmailFrame, 1, 2, 2, 3,
gtk.FILL, gtk.EXPAND | gtk.SHRINK | gtk.FILL, 0, 0)
recipientEmailFrame.show()
recipientEmailEntry = gtk.Entry()
dataTable.attach(recipientEmailEntry, 1, 2, 3, 4,
gtk.FILL, gtk.EXPAND | gtk.SHRINK | gtk.FILL, 0, 0)
recipientEmailEntry.show()
dataAndTimeFrame = gtk.Label("Data and Time:")
dataTable.attach(dataAndTimeFrame, 0, 1, 4, 5,
gtk.FILL, gtk.EXPAND | gtk.SHRINK | gtk.FILL, 0, 0)
dataAndTimeFrame.show()
dataAndTimeEntry = gtk.Entry()
dataTable.attach(dataAndTimeEntry, 1, 2, 4, 5,
gtk.FILL, gtk.EXPAND | gtk.SHRINK | gtk.FILL, 0, 0)
dataAndTimeEntry.show()
subjectFrame = gtk.Label("Subject:")
dataTable.attach(subjectFrame, 0, 1, 5, 6,
gtk.FILL, gtk.EXPAND | gtk.SHRINK | gtk.FILL, 0, 0)
subjectFrame.show()
subjectEntry = gtk.Entry()
dataTable.attach(subjectEntry, 1, 2, 5, 6,
gtk.FILL, gtk.EXPAND | gtk.SHRINK | gtk.FILL, 0, 0)
subjectEntry.show()
####################################################################
# FRAME 2 ##########################################################
self.frame2 = gtk.Frame()
self.contentTable.attach(self.frame2,0,1,1,2,
gtk.FILL, gtk.EXPAND | gtk.SHRINK | gtk.FILL, 0, 0)
self.frame2.set_label_align(0.0, 0.0)
self.frame2.set_label("Enter message body")
self.frame2.set_shadow_type(gtk.SHADOW_ETCHED_OUT)
self.frame2.show()
table = gtk.ScrolledWindow()
table.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
text = gtk.TextView()
text.set_editable(True)
textbuffer = text.get_buffer()
self.frame2.add(table)
table.show()
table.add(text)
text.show()
####################################################################
# FRAME 3 ##########################################################
self.frame3 = gtk.Frame()
self.contentTable.attach(self.frame3,0,1,2,3,
gtk.FILL, gtk.EXPAND | gtk.SHRINK | gtk.FILL, 0, 0)
self.frame3.set_label_align(0.0, 0.0)
self.frame3.set_label("Select attached files")
self.frame3.set_shadow_type(gtk.SHADOW_ETCHED_OUT)
self.frame3.show()
####################################################################
self.contentTable.show()
self.window.show()
def main(self):
gtk.main()
def destroy(self, widget, data=None):
gtk.main_quit()
我认为问题出在gtk.box参数或gtk.tables的参数中。我已经尝试了一切,没有任何改变。 在网上找到关于gtk和python的例子,一切都和我一样,但结果总是和我的不一样。
答案 0 :(得分:1)
调用contentTable.attach时,您必须将gtk.EXPAND添加到xoptions参数:
# FRAME 1 ##########################################################
self.frame1 = gtk.Frame()
self.contentTable.attach(self.frame1, 0, 1, 0, 1,
gtk.FILL | gtk.EXPAND, gtk.EXPAND | gtk.SHRINK | gtk.FILL, 0, 0)