How to create window in desktop application
This is simplest program or just a starter. This program
consist window 200x200 pixel window. When you run it on pygtk environment, then
it will open one 200x200 pixel window.
#!/usr/bin/env
python
#
base.py
import
pygtk
pygtk.require('2.0')
import
gtk
class
Base:
def __init__(self):
self.window =
gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_icon_from_file('images/favicon.gif')
self.window.set_title("Sample
window")
self.window.set_position(gtk.WIN_POS_CENTER)
self.window.set_size_request(500, 275)
self.window.set_resizable(False)
self.window.show()
def main(self):
gtk.main()
print
__name__
if
__name__ == "__main__":
base = Base()
base.main()
Window attributes:
- self.window.set_icon_from_file('images/favicon.gif')-It is for window favicon icon.
- self.window.set_title("Sample window")—This is window title.
- self.window.set_position(gtk.WIN_POS_CENTER)-popup window will come in center or according to position.
- self.window.set_size_request(500, 275)—It will open window with size 500x275 pixel.
- self.window.set_resizable(False)-It will disable maximize.
- set_border_width(10)- It adjust Window width from all the sides.
- self.window.connect("expose_event", self.expose)- expose event is nothing but hovering means when you keep curser on window, self.expose function will call and self is showing that this function is present in same class and self is just like as class object.
- __init__()- it is a default constructor which will be call at the time of creating class object.
No comments:
Post a Comment