Merge lp:~williamdoyleaf/python-snippets/window-snippets into lp:~jonobacon/python-snippets/trunk

Proposed by William Doyle
Status: Needs review
Proposed branch: lp:~williamdoyleaf/python-snippets/window-snippets
Merge into: lp:~jonobacon/python-snippets/trunk
Diff against target: 92 lines (+88/-0)
1 file modified
pygtk/child_window.py (+88/-0)
To merge this branch: bzr merge lp:~williamdoyleaf/python-snippets/window-snippets
Reviewer Review Type Date Requested Status
Jono Bacon Pending
Review via email: mp+69471@code.launchpad.net

Description of the change

Added a pygtk program to call a child window by clicking on a button in main window. I hope this will be a help to those who start learning python programming. I started learning python nearly one month back an found it difficult to figure out such things as a novice.

To post a comment you must log in.

Unmerged revisions

100. By william doyle <william@william-desktop>

This is my first commit -a program to call a child window.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'pygtk/child_window.py'
2--- pygtk/child_window.py 1970-01-01 00:00:00 +0000
3+++ pygtk/child_window.py 2011-07-27 14:16:37 +0000
4@@ -0,0 +1,88 @@
5+#!/usr/bin/env python
6+#
7+# [SNIPPET_NAME: Create Child Window]
8+# [SNIPPET_CATEGORIES: PyGTK]
9+# [SNIPPET_DESCRIPTION: Create a child window on clicking a button in parent window]
10+# [SNIPPET_AOUTHER: William Doyle A F]
11+# [SNIPPET_DOCS:http://www.pygtk.org/pygtk2tutorials.html]
12+# [SNIPPET_LICENCE: GPL]
13+
14+import pygtk
15+pygtk.require('2.0')
16+import gtk
17+
18+class main_window():
19+ def __init__(self,cwin):
20+ #Create parent window
21+ self.mw=gtk.Window(gtk.WINDOW_TOPLEVEL)
22+ self.mw.set_title("Main window")
23+ self.mw.set_position(gtk.WIN_POS_CENTER)
24+ #Connect the destroy signal to gtk.main_quit
25+ self.mw.connect("destroy",self.destroy,None)
26+ self.mw.show()
27+
28+ #Create a vericle box
29+ self.vbox=gtk.VBox(False,0)
30+ self.mw.add(self.vbox)
31+ self.vbox.show()
32+
33+ #Create a button
34+ self.button=gtk.Button("Call Child window")
35+ self.vbox.pack_start(self.button,False,False,0)
36+
37+ #Connect the button click to call the child window
38+ self.button.connect("clicked",self.call_back,cwin)
39+ self.button.show()
40+
41+ def destroy(self, widget, data=None):
42+ gtk.main_quit()
43+
44+ def call_back(self,widget,cwin):
45+ self.button.set_sensitive(False)
46+ cwin.hello_child(self.button)
47+
48+class child_window():
49+ def hello_child(self,b):
50+ #Create the child window
51+ self.cw=gtk.Window(gtk.WINDOW_TOPLEVEL)
52+ self.cw.set_default_size(200,150)
53+ self.cw.set_title("Child window")
54+
55+ #Connect the destroy signal to gtk.main_quit
56+ self.cw.connect("destroy",self.destroy,b)
57+
58+ #Create a vericle box
59+ self.vbox=gtk.VBox(False,0)
60+ self.cw.add(self.vbox)
61+ self.vbox.show()
62+
63+ #Create a button
64+ self.button=gtk.Button("Press Me")
65+ self.vbox.pack_start(self.button,False,False,0)
66+ self.button.connect("clicked",self.child_button_callback,None)
67+ self.button.show()
68+
69+ self.cw.show()
70+ print "hello from child"
71+
72+
73+ def destroy(self,widget,b):
74+ b.set_sensitive(True)
75+ print "Child window say bye"
76+
77+
78+ def child_button_callback(self,widget,data=None):
79+ print "Child button clicked"
80+
81+
82+
83+def main():
84+
85+ cwin=child_window()
86+ mwin=main_window(cwin)
87+
88+ gtk.main()
89+
90+if __name__=="__main__":
91+
92+ main()

Subscribers

People subscribed via source and target branches