Python PyGTK-如何使用此表格布局来匹配背景图像?
这是我尝试的,但有些行的设计不同。为什么我不能正确地放置按钮,知道如何修复吗 这是背景图像: 代码如下所示:Python PyGTK-如何使用此表格布局来匹配背景图像?,python,python-2.7,gtk,pygtk,gnome,Python,Python 2.7,Gtk,Pygtk,Gnome,这是我尝试的,但有些行的设计不同。为什么我不能正确地放置按钮,知道如何修复吗 这是背景图像: 代码如下所示: #!/usr/bin/python import gtk class PyApp(gtk.Window): def createButton(self, name, funreturn): button_height= 32 button = gtk.Button() button.props.relief = gtk.RELIEF_NO
#!/usr/bin/python
import gtk
class PyApp(gtk.Window):
def createButton(self, name, funreturn):
button_height= 32
button = gtk.Button()
button.props.relief = gtk.RELIEF_NONE
label = gtk.Label()
label.set_markup('<span color="#ffffff"><small>' + name + '</small></span>')
button.add(label)
button.set_name("deButton")
button.connect("clicked" , funreturn , None)
button.set_size_request(48, button_height)
return button
def callback(self):
print "none"
def __init__(self):
super(PyApp, self).__init__()
""" Window """
button_rc = """
pixmap_path "/var/tmp"
### Background > Image
style "window" {
bg_pixmap[NORMAL] = "menu/keyboard_new.png"
}
style "deButton" {
fg[PRELIGHT] = { 0, 1.0, 1.0 }
bg[PRELIGHT] = { 0, 0, 1.0 }
bg[ACTIVE] = { 1.0, 0, 0 }
fg[ACTIVE] = { 0, 1.0, 0 }
bg[NORMAL] = { 1.0, 1.0, 0 }
fg[NORMAL] = { .99, 0, .99 }
bg[INSENSITIVE] = { 1.0, 1.0, 1.0 }
fg[INSENSITIVE] = { 1.0, 0, 1.0 }
engine "pixmap" {
image {
function = BOX
file = "menu/commonbutton1.png"
stretch = TRUE
}
}
bg_pixmap[NORMAL] = "menu/commonbutton1.png"
}
# imports
widget "*.deButton" style "deButton"
widget_class "*GtkButton*" style "button"
widget_class "GtkWindow" style "window"
"""
self.set_title("Keyboard")
self.set_size_request(600, 300)
self.set_position(gtk.WIN_POS_CENTER)
gtk.rc_parse_string(button_rc)
vbox = gtk.VBox(False, 2)
table = gtk.Table(5, 10, True)
table.attach(self.createButton("1",self.callback), 0, 1, 0, 1)
table.attach(self.createButton("2",self.callback), 1, 2, 0, 1)
table.attach(self.createButton("3",self.callback), 2, 3, 0, 1)
table.attach(self.createButton("4",self.callback), 3, 4, 0, 1)
table.attach(self.createButton("5",self.callback), 4, 5, 0, 1)
table.attach(self.createButton("6",self.callback), 5, 6, 0, 1)
table.attach(self.createButton("7",self.callback), 6, 7, 0, 1)
table.attach(self.createButton("8",self.callback), 7, 8, 0, 1)
table.attach(self.createButton("9",self.callback), 8, 9, 0, 1)
table.attach(self.createButton("0",self.callback), 9, 10, 0, 1)
table.attach(self.createButton("Q",self.callback), 0, 1, 1,2)
table.attach(self.createButton("W",self.callback), 1, 2, 1, 2)
table.attach(self.createButton("E",self.callback), 2, 3, 1, 2)
table.attach(self.createButton("R",self.callback), 3, 4, 1, 2)
table.attach(self.createButton("T",self.callback), 4, 5, 1, 2)
table.attach(self.createButton("Y",self.callback), 5, 6, 1, 2)
table.attach(self.createButton("U",self.callback), 6, 7, 1, 2)
table.attach(self.createButton("I",self.callback), 7, 8, 1, 2)
table.attach(self.createButton("O",self.callback), 8, 9, 1, 2)
table.attach(self.createButton("P",self.callback), 9, 10, 1, 2)
table.attach(self.createButton("A",self.callback), 0, 1, 2,3)
table.attach(self.createButton("S",self.callback), 1, 2, 2, 3)
table.attach(self.createButton("D",self.callback), 2, 3, 2, 3)
table.attach(self.createButton("F",self.callback), 3, 4, 2, 3)
table.attach(self.createButton("G",self.callback), 4, 5, 2, 3)
table.attach(self.createButton("H",self.callback), 5, 6, 2, 3)
table.attach(self.createButton("J",self.callback), 6, 7, 2, 3)
table.attach(self.createButton("K",self.callback), 7, 8, 2, 3)
table.attach(self.createButton("L",self.callback), 8, 9, 2, 3)
table.attach(self.createButton("",self.callback), 9, 10, 2, 3)
#vbox.pack_start(gtk.Entry(), False, False, 0)
vbox.pack_end(table, True, True, 0)
self.add(vbox)
self.connect("destroy", gtk.main_quit)
self.show_all()
PyApp()
gtk.main()
#/usr/bin/python
进口gtk
PyApp类(gtk.窗口):
def createButton(self、name、funreturn):
按钮高度=32
button=gtk.button()
button.props.relief=gtk.relief\u无
label=gtk.label()
label.set_标记(“”+name+“”)
按钮。添加(标签)
按钮。设置名称(“去毛刺”)
按钮。连接(“单击”,返回,无)
按钮。设置大小请求(48,按钮高度)
返回按钮
def回调(自):
打印“无”
定义初始化(自):
超级(PyApp,self)。\uuuu init
“窗口”
按钮_rc=“”
pixmap_路径“/var/tmp”
###背景>图像
样式“窗口”{
bg_pixmap[NORMAL]=“菜单/键盘\u new.png”
}
风格“去毛刺”{
fg[PRELIGHT]={0,1.0,1.0}
bg[PRELIGHT]={0,0,1.0}
bg[ACTIVE]={1.0,0,0}
fg[ACTIVE]={0,1.0,0}
bg[正常]={1.0,1.0,0}
fg[正常]={.99,0,99}
bg[不敏感]={1.0,1.0,1.0}
fg[不敏感]={1.0,0,1.0}
引擎“pixmap”{
形象{
函数=框
file=“menu/commonbutton1.png”
拉伸=真
}
}
bg_pixmap[NORMAL]=“menu/commonbutton1.png”
}
#进口
小部件“*.deButton”样式“deButton”
控件类“*GTK按钮*”样式“按钮”
widget_类“GtkWindow”样式“窗口”
"""
自我设置标题(“键盘”)
自我设置大小请求(600300)
自我设置位置(gtk.WIN位置中心)
gtk.rc_解析_字符串(按钮_rc)
vbox=gtk.vbox(False,2)
表=gtk.表(5,10,真)
table.attach(self.createButton(“1”,self.callback),0,1,0,1)
table.attach(self.createButton(“2”,self.callback),1,2,0,1)
table.attach(self.createButton(“3”,self.callback),2,3,0,1)
table.attach(self.createButton(“4”,self.callback),3,4,0,1)
table.attach(self.createButton(“5”,self.callback),4,5,0,1)
table.attach(self.createButton(“6”,self.callback),5,6,0,1)
table.attach(self.createButton(“7”,self.callback),6,7,0,1)
table.attach(self.createButton(“8”,self.callback),7,8,0,1)
table.attach(self.createButton(“9”,self.callback),8,9,0,1)
table.attach(self.createButton(“0”,self.callback),9,10,0,1)
table.attach(self.createButton(“Q”,self.callback),0,1,1,2)
table.attach(self.createButton(“W”,self.callback),1,2,1,2)
table.attach(self.createButton(“E”,self.callback),2,3,1,2)
table.attach(self.createButton(“R”,self.callback),3,4,1,2)
table.attach(self.createButton(“T”,self.callback),4,5,1,2)
table.attach(self.createButton(“Y”,self.callback),5,6,1,2)
table.attach(self.createButton(“U”,self.callback),6,7,1,2)
table.attach(self.createButton(“I”,self.callback),7,8,1,2)
table.attach(self.createButton(“O”,self.callback),8,9,1,2)
table.attach(self.createButton(“P”,self.callback),9,10,1,2)
table.attach(self.createButton(“A”,self.callback),0,1,2,3)
table.attach(self.createButton(“S”,self.callback),1,2,2,3)
table.attach(self.createButton(“D”,self.callback),2,3,2,3)
table.attach(self.createButton(“F”,self.callback),3,4,2,3)
附加表(self.createButton(“G”,self.callback),4,5,2,3)
附加(self.createButton(“H”,self.callback),5,6,2,3)
附加表(self.createButton(“J”,self.callback),6,7,2,3)
table.attach(self.createButton(“K”,self.callback),7,8,2,3)
table.attach(self.createButton(“L”,self.callback),8,9,2,3)
table.attach(self.createButton(“,self.callback)),9,10,2,3)
#vbox.pack_start(gtk.Entry(),False,False,0)
vbox.pack_end(表,真,真,0)
self.add(vbox)
自我连接(“销毁”,gtk.main_退出)
self.show_all()
PyApp()
gtk.main()
正常-工作正常,最好使用固定小部件,而不是表格或网格
#!/usr/bin/python
import gtk
class PyApp(gtk.Window):
def __init__(self):
super(PyApp, self).__init__()
""" Window - Background embed """
button_rc = """
pixmap_path "/var/tmp"
# Button - image apply
style "window" {
bg_pixmap[NORMAL] = "menu/keyboard_new.png"
}
style "deButton" {
fg[PRELIGHT] = { 0, 1.0, 1.0 }
bg[PRELIGHT] = { 0, 0, 1.0 }
bg[ACTIVE] = { 1.0, 0, 0 }
fg[ACTIVE] = { 0, 1.0, 0 }
bg[NORMAL] = { 1.0, 1.0, 0 }
fg[NORMAL] = { .99, 0, .99 }
bg[INSENSITIVE] = { 1.0, 1.0, 1.0 }
fg[INSENSITIVE] = { 1.0, 0, 1.0 }
engine "pixmap" {
image {
function = BOX
file = "menu/commonbutton1.png"
stretch = TRUE
}
}
bg_pixmap[NORMAL] = "menu/commonbutton1.png"
}
# imports
widget "*.deButton" style "deButton"
widget_class "*GtkButton*" style "button"
widget_class "GtkWindow" style "window"
"""
self.set_title("Keyboard")
self.set_size_request(600, 300)
self.set_position(gtk.WIN_POS_CENTER)
gtk.rc_parse_string(button_rc) ##<<<<< include the design
vbox = gtk.VBox(False, 2)
fix = gtk.Fixed() ## YumYumYum
""" Row 1 """
fix.put( gtk.Button("1") , 20 , 20 )
fix.put( gtk.Button("2") , 80 , 20 )
fix.put( gtk.Button("3") , 150 , 20 )
""" Row 2 """
fix.put( gtk.Button("Q") , 20 , 80 )
""" Row 3 """
fix.put( gtk.Button("A") , 60 , 130 )
""" Row 4 """
fix.put( gtk.Button("Z") , 60 , 190 )
""" Row 5 """
fix.put( gtk.Button("SPACE") , 180 , 240 )
vbox.pack_end(fix, True, True, 0)
self.add(vbox)
self.connect("destroy", gtk.main_quit)
self.show_all()
PyApp()
gtk.main()
#/usr/bin/python
进口gtk
PyApp类(gtk.窗口):
定义初始化(自):
超级(PyApp,self)。\uuuu init
“”“窗口-背景嵌入”“”
按钮_rc=“”
pixmap_路径“/var/tmp”
#按钮-图像应用
样式“窗口”{
bg_pixmap[NORMAL]=“菜单/键盘\u new.png”
}
风格“去毛刺”{
fg[PRELIGHT]={0,1.0,1.0}
bg[PRELIGHT]={0,0,1.0}
bg[ACTIVE]={1.0,0,0}
fg[ACTIVE]={0,1.0,0}
bg[正常]={1.0,1.0,0}
fg[正常]={.99,0,99}
bg[不敏感]={1.0,1.0,1.0}
fg[不敏感]={1.0,0,1.0}
引擎“pixmap”{
形象{
函数=框
file=“menu/commonbutton1.png”
拉伸=真
}
}
bg_pixmap[NORMAL]=“menu/commonbutton1.png”
}
#进口
小部件“*.deButton”样式“deButton”
控件类“*GTK按钮*”样式“按钮”
widget_类“GtkWindow”样式“窗口”
"""
自我设置标题(“键盘”)
自我设置大小请求(600300)
自我设置位置(gtk.WIN位置中心)
gtk.rc_parse_string(button_rc)##OK-可以工作,最好使用固定小部件而不是表格或网格
#!/usr/bin/python
import gtk
class PyApp(gtk.Window):
def __init__(self):
super(PyApp, self).__init__()
""" Window - Background embed """
button_rc = """
pixmap_path "/var/tmp"
# Button - image apply
style "window" {
bg_pixmap[NORMAL] = "menu/keyboard_new.png"
}
style "deButton" {
fg[PRELIGHT] = { 0, 1.0, 1.0 }
bg[PRELIGHT] = { 0, 0, 1.0 }
bg[ACTIVE] = { 1.0, 0, 0 }
fg[ACTIVE] = { 0, 1.0, 0 }
bg[NORMAL] = { 1.0, 1.0, 0 }
fg[NORMAL] = { .99, 0, .99 }
bg[INSENSITIVE] = { 1.0, 1.0, 1.0 }
fg[INSENSITIVE] = { 1.0, 0, 1.0 }
engine "pixmap" {
image {
function = BOX
file = "menu/commonbutton1.png"
stretch = TRUE
}
}
bg_pixmap[NORMAL] = "menu/commonbutton1.png"
}
# imports
widget "*.deButton" style "deButton"
widget_class "*GtkButton*" style "button"
widget_class "GtkWindow" style "window"
"""
self.set_title("Keyboard")
self.set_size_request(600, 300)
self.set_position(gtk.WIN_POS_CENTER)
gtk.rc_parse_string(button_rc) ##<<<<< include the design
vbox = gtk.VBox(False, 2)
fix = gtk.Fixed() ## YumYumYum
""" Row 1 """
fix.put( gtk.Button("1") , 20 , 20 )
fix.put( gtk.Button("2") , 80 , 20 )
fix.put( gtk.Button("3") , 150 , 20 )
""" Row 2 """
fix.put( gtk.Button("Q") , 20 , 80 )
""" Row 3 """
fix.put( gtk.Button("A") , 60 , 130 )
""" Row 4 """
fix.put( gtk.Button("Z") , 60 , 190 )
""" Row 5 """
fix.put( gtk.Button("SPACE") , 180 , 240 )
vbox.pack_end(fix, True, True, 0)
self.add(vbox)
self.connect("destroy", gtk.main_quit)
self.show_all()
PyApp()
gtk.main()
#/usr/bin/python
进口gtk
PyApp类(gtk.窗口):
定义初始化(自):
超级(PyApp,self)。\uuuu init
“窗口-背景”