Advertisement

05.06.2008 at 04:28PM PDT, ID: 23381249
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.5

How do you retrieve input from a Python-GTK GUI class

Asked by lwdalton3 in Python Scripting Language, Linux, Fedora Linux

Tags: , ,

This is a next step question based on a post a few days back. I am trying to learn to use Python with GTK. I am using the tutorial   found at   http://www.pygtk.org/pygtk2tutorial/sec-TextEntries.html
authored compliments of John Finlay. The snippet is a modification of what is found at the above link. I managed to go from one box to three!  The snippet ran fine under my Linux Fedora 7 environment. Anyhow, not explained in the tutorial is how to retrieve data from the GUI class into I guess what would be equivelant to main in C++ -- the guts of the program. I am trying to build various calculators and need to retrieve data from boxes and post the answers back into some other boxes-- pretty simple stuff it would seem. The attachyed snippet construct three boxes-- entry, entry2 and entry 3. How would one say take "Goodnight" from entry and "Moon" from entry2 and concatenate back into entry3 "Goodnight Moon" ? Thanks for your help. LD Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
#!/usr/bin/env python
    
# example entry.py
 
import pygtk
pygtk.require('2.0')
import gtk
    
class EntryExample:
    def enter_callback(self, widget, entry):
          entry_text = entry.get_text()
          print "Entry contents: %s\n" % entry_text
        
      def __init__(self):
            # create a new window
            window = gtk.Window(gtk.WINDOW_TOPLEVEL)
            window.set_size_request(200, 100)
            window.set_title("GTK Entry")
            window.connect("delete_event", lambda w,e: gtk.main_quit())
    
            vbox = gtk.VBox(False, 0)
            window.add(vbox)
            vbox.show()
    
            entry = gtk.Entry()
            entry.set_max_length(50)
            entry.connect("activate", self.enter_callback, entry)
            entry.set_text("enter")
            entry.insert_text(" number", len(entry.get_text()))
            entry.select_region(0, len(entry.get_text()))
            vbox.pack_start(entry, True, True, 0)
            entry.show()
 
        entry2 = gtk.Entry()
            entry2.set_max_length(50)
            entry2.connect("activate", self.enter_callback, entry2)
            entry2.set_text("add")
            entry2.insert_text(" number", len(entry2.get_text()))
            entry2.select_region(0, len(entry2.get_text()))
            vbox.pack_start(entry2, True, True, 0)
            entry2.show()
 
        entry3 = gtk.Entry()
            entry3.set_max_length(50)
            entry3.connect("activate", self.enter_callback, entry3)
            entry3.set_text("answer")
            entry3.insert_text(" here", len(entry3.get_text()))
            entry3.select_region(0, len(entry3.get_text()))
            vbox.pack_start(entry3, True, True, 0)
            entry3.show()
    
    
            hbox = gtk.HBox(False, 0)
            vbox.add(hbox)
            hbox.show()
                                      
            button = gtk.Button(stock=gtk.STOCK_CLOSE)
            button.connect("clicked", lambda w: gtk.main_quit())
            vbox.pack_start(button, True, True, 0)
            button.set_flags(gtk.CAN_DEFAULT)
            button.grab_default()
            button.show()
            window.show()
    
def main():
    gtk.main()
    return 0
        
if __name__ == "__main__":
    EntryExample()
    main()
 
print "I would what is in the entry.get_text() here "
[+][-]05.07.2008 at 03:02PM PDT, ID: 21520737

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Python Scripting Language, Linux, Fedora Linux
Tags: Python GTK open source, Python, most recent
Sign Up Now!
Solution Provided By: RichieHindle
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20081112-EE-VQP-43 / EE_QW_2_20070628