Hello everyone, I'm new to this forum and a sort of beginner at Python. I've created a GUI in Python using Glade and GTK and I have two questions. I'm having trouble with comboboxes. Particularly with entering data into a combo box from Python. I've tried the following.... -
myCombo = self.wTree.get_widget('comboboxentry')
-
myCombo.append_text('blah blah blah')
-
to no avail... apparently you have to first do gtk.combo_box_new_text() before you can append text. Is this possible when using Glade to construct my GUI?
My second question is this.. How do I create a ListBox using Glade or GTK. I would like eventually to be able to grab text from a line via mouse click. For example, a list of files appear in a text area and the user would be able to double click on the file and be able to delete it etc... Any help would be greatly appreciated. Thank you.
4 13523
I'm not sure this forum actually has any GTK experts.
The closest that I have come to using tools such as yours was way back when I first started using wxPython. My first GUI generator was wxGlade, but I understand that the two projects are not related (code-wise).
Sorry that I couldn't be of more assistance.
You could use a treeview.
Use Glade to create a window with a treeview and a button.
Add a destroy signal for the window and a clicked signal for the button.
Save as test.glade.
Here is a python example that you can run from a terminal: -
-
import pygtk
-
pygtk.require("2.0")
-
import gtk, gtk.glade
-
-
data=[["USD","American Dollar",0.748223],
-
["GBP","British Pound",1.47886],
-
["CAD","Canadian Dollar",0.700714],
-
["EUR","Euro",1.0],
-
["AUD","Australian Dollar",0.628505]]
-
-
-
class test:
-
def __init__(self):
-
-
#get the widget tree from the Glade file
-
self.tree=gtk.glade.XML ("test.glade","window1")
-
-
#connect the signals to the callbacks
-
self.tree.signal_autoconnect (self)
-
-
#load the data into a ListStore
-
-
store=gtk.ListStore(str,str,float)
-
for row in data:
-
store.append(row)
-
-
#find the treeview widget and link to the store
-
self.view=self.tree.get_widget("treeview1")
-
self.view.set_model(store)
-
-
#create the columns for the treeview
-
render=gtk.CellRendererText()
-
col=gtk.TreeViewColumn("Code",render,text=0)
-
self.view.append_column(col)
-
render=gtk.CellRendererText()
-
col=gtk.TreeViewColumn("Name",render,text=1)
-
self.view.append_column(col)
-
render=gtk.CellRendererText()
-
col=gtk.TreeViewColumn("Rate",render,text=2)
-
self.view.append_column(col)
-
-
#set the selection option so that only one row can be selected
-
sel=self.view.get_selection()
-
sel.set_mode(gtk.SELECTION_SINGLE)
-
-
#show the treeview
-
self.view.show()
-
-
-
-
-
#here are the callbacks
-
-
-
def on_window1_destroy(self,w):
-
print "window1_destroy"
-
gtk.main_quit()
-
-
def on_button1_clicked(self,w):
-
print "button1_clicked"
-
#find which row was selected (if any)
-
sel=self.view.get_selection()
-
(model,iter)=sel.get_selected()
-
-
#print result
-
if iter == None:
-
print "no row selected"
-
else :
-
print list(model[iter])
-
#finish
-
gtk.main_quit()
-
-
-
test()
-
gtk.main()
-
Here is a combobox version
You can put a list of strings in the combobox during the Glade session, or you can replace this with your own list of strings in the program -
#!/usr/bin/env python
-
-
import pygtk
-
pygtk.require('2.0')
-
import gtk, gtk.glade
-
-
data=["harry","pat","june","sarah","william"]
-
-
class cbtest:
-
def __init__(self):
-
-
#get the widget tree from the Glade file
-
self.tree=gtk.glade.XML ("cbtest.glade","window1")
-
-
#connect the signals to the callbacks
-
self.tree.signal_autoconnect (self)
-
-
#find the combobox widget in the widget tree
-
self.box=self.tree.get_widget("combobox1")
-
-
-
#if you set up the string list in Glade, than you can miss this next bit.
-
#but if you want to set up the string list from the program:
-
store=gtk.ListStore(str)
-
store.append(["Choose a name"])
-
for d in data:
-
store.append([d]) #note: append a list
-
self.box.set_model(store) #this replaces the model set by Glade
-
-
#make the first row active
-
self.box.set_active(0)
-
-
# you must have set a changed signal for combobox1 in cbtest.glade
-
def on_combobox1_changed(self, box):
-
model = box.get_model()
-
index = box.get_active()
-
if index:
-
print model[index][0], 'selected'
-
-
def on_window1_destroy(self,w):
-
gtk.main_quit()
-
-
-
if __name__ == "__main__":
-
cbtest()
-
gtk.main()
-
francp, you are awesome! Thank you so much for posting in the Python forum.
This is the first chance that I have gotten to see what the GTK interface looks like in practice.
I hope to see more Q&A on the subject in the future.
Thanks, again, for joining the Python Forum on TheScripts.com,
Barton
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Hans Deragon |
last post by:
Greetings.
Total newbie to Glade here. I created an interface using glade-2
and I want to use it with my python program. Following is what I
wrote (test prg):
-------------------------...
|
by: Will Ware |
last post by:
In July there was a thread about problems on Red Hat 9 with PyGTK
not playing nice with Glade. I was tinkering with this a little bit
tonight, starting with the code I found in this article:...
|
by: P. Jouin |
last post by:
I work with Linux Mandrake10 and KDE. I have compiled and install :
Python 2.3.4
pygtk-2.2.0
Glade2 2.6.0
My problem is : I want to know what can i do for having Python in the
Language of...
|
by: somesh |
last post by:
hello,
I wrote a small tute for my brother to teach him python + glade,
plz see, and suggest to make it more professional ,
In tute I discussed on Glade + Python for developing Applications too...
|
by: Doug |
last post by:
Hi all,
Can someone tell me why I do not get a connection between the events and
the functions in the sample below. GUI window appears OK, just no
connections seem to be made.
I am new to this...
|
by: Terry Hancock |
last post by:
I've run into something a little odd on my Debian-installed
Python 2.3.
I have deb packages "python2.3", "python-gtk2", and
"python2.3-glade2" installed on this machine. Among other
things,...
|
by: Kveldulv |
last post by:
I made simple GUI in Glade 3 (Ubuntu 7.04) consisting of only 2
buttons. When I run
2buttonsgui.py, no GUI pops out
#!/usr/bin/env python
import pygtk
import gtk.glade
class TwoButtonsGUI:...
|
by: Greg Johnston |
last post by:
Hey all,
I'm a relative newbie to Python (switched over from Scheme fairly
recently) but I've been using PyGTK and Glade to create an interface,
which is a combo I'm very impressed with.
...
|
by: holmes86 |
last post by:
hi,everyone.
I am a python newbie.and I write a python program with glade,as following:
import sys
import gtk
import gtk.glade
class TLaitSignals:
'''Define TLait singals handler'''
|
by: lllomh |
last post by:
Define the method first
this.state = {
buttonBackgroundColor: 'green',
isBlinking: false, // A new status is added to identify whether the button is blinking or not
}
autoStart=()=>{
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: giovanniandrean |
last post by:
The energy model is structured as follows and uses excel sheets to give input data:
1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
| |