[pygtk] Very Simple PyGTK project from a newbie

Syed Husain faustus.eee at gmail.com
Wed Feb 1 10:42:16 WST 2012


Hello everyone,

i am quite new in using Pygtk. so be nice:-) . i have created this simple
temperature converter that works fine. but the problem i am having is that
i can convert only one number at a time. i want my program running
continuously until i click the "EXIT" button i created in my window.

i have attached my code in a text file.

any help will be appreciated.

regards,

Syed


here is the code:

*#!/usr/bin/env python

import pygtk
pygtk.require('2.0')
import gtk

class Temperature_Converter:
		
	#this method will destroy the window
	def destroy(self,widget,data=None):
		print "Closed Successfully"
		gtk.main_quit()

	#the method is for converting from C to F
	def C2F(self,widget,x=10):
		self.x = x
		x = (5.0/9)*(self.Temperature-32)
		print "C2F: %f" %x

	#this method is for converting from F to C
	def F2C(self,widget,y=5):
		self.y = y
		y = (9.0/5)*self.Temperature+32
		print "F2C: %f" %y

	#def textchange(self,widget):
		#self.label.set_text(self.textbox.get_text())
	
	
	def __init__(self,Temperature):
		self.Temperature = Temperature
		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		self.window.set_position(gtk.WIN_POS_CENTER_ALWAYS)
		self.window.set_size_request(600,100)
		
		self.button1 = gtk.Button("EXIT")
		self.button1.connect("clicked",self.destroy)	
		
		self.button2 = gtk.Button("C2F")
		self.button2.connect("clicked",self.C2F)	
		
		self.button3 = gtk.Button("F2C")
		self.button3.connect("clicked",self.F2C)	
		
		#self.textbox = gtk.Entry()
		#self.textbox.connect("changed",self.textchange)
		#self.butto4 = gtk.Button("Main")
		#self.button4.connect("clicked",self.main)		
		#self.label = gtk.Label("Number")
				
		self.box1 = gtk.VBox()
		self.box1.pack_start(self.button1)
		self.box1.pack_start(self.button2)
		self.box1.pack_start(self.button3)	
		#self.box1.pack_start(self.button4)	
		#self.box1.pack_start(self.textbox)
		#self.box1.pack_start(self.label)			
						
		
		self.window.add(self.box1)
		
		self.window.show_all()
		self.window.connect("destroy",self.destroy)	
	

	def main(self):
		#z = float(raw_input("Enter a number: "))	
		gtk.main()

if __name__ == "__main__":

	a = float(raw_input("Enter a Number to Convert: "))
	#Class Instance
	base =Temperature_Converter(a)
	base.main()*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.daa.com.au/pipermail/pygtk/attachments/20120201/d11a69b2/attachment.html>


More information about the pygtk mailing list