Ex. No. :3
|
IMPLEMENTATION OF GUI PROGRAM
|
AIM:
To write python program to implement GUI
INTRODUCTION :
GUI programming on Linux is based on the X Window system. X provides windowing oncomputer displays and manages keyboard, pointing device control functions and touch-screens. X provides the basic framework, or primitives, for building such GUI environments: drawing and moving windows on the display and interacting with a mouse, keyboard or touchscreen. X uses GUI toolkits to help the development of GUI programs. GUI toolkit is a set of widgets for use in designing applications with graphical user interfaces (GUIs). GUI toolkits can be based on different languages. The most commonly used languages are C/C++. Often the toolkits provide higher level language bindings which allow the user to program GUIs using an easier to use higher level language like Python, Ruby etc.
There are two popular GUI toolkits which are widely used today. They are Qt and GTK+.
Qt is written in C++ while GTK+ is written in C. Both toolkits provide bindings in a wide variety of languages.For users who are familiar with Visual basic, Gambas is a full-featured object language
and development environment built on a BASIC interpreter which runs on top of the X window system. It in turn relies on the underlying GUI toolkits (both Qt and GTk+).
PROGRAM
Write a Python script that creates a button with the text "Hello World".
import pygtk
pygtk.require('2.0')
import gtk
class HelloWorld:
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_border_width(5)
self.button = gtk.Button("Hello World!")
self.window.add(self.button)
self.window.show_all()
def main(self):
gtk.main()
if __name__ == "__main__":
hello = HelloWorld()
hello.main()
OUTPUT
PROGRAM USING CALL BACK
#!/usr/bin/env python
import pygtk
pygtk.require('2.0')
import gtk
class HelloWorld:
def on_button_clicked(self, widget, data=None):
print "Hello World"
def on_window_destroy(self, widget, data=None):
gtk.main_quit()
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.connect("destroy", self.on_window_destroy)
self.window.set_border_width(5)
self.button = gtk.Button("Hello World")
self.button.connect("clicked", self.on_button_clicked)
self.window.add(self.button)
self.window.show_all()
def main(self):
gtk.main()
if __name__ == "__main__":
hello = HelloWorld()
hello.main()
OUTPUT
RESULT:
Thus python program to GUI was implemented
--
Don't ever give up.
Even when it seems impossible,
Something will always
pull you through.
The hardest times get even
worse when you lose hope.
As long as you believe you can do it, You can.
But When you give up,
You lose !
I DONT GIVE UP.....!!!
with regards
prem sasi kumar arivukalanjiam
No comments:
Post a Comment