Thursday, February 23, 2017

Simple Addition of two value using Python and Tk GUI

Python provides various options for developing graphical user interfaces (GUIs). Tkinter, wxPython and JPython is wellknow.
Tkinter comes in build with Python package and it provide most of the GUI component like canvas, button, checkbox, radiobutton, button etc.
In below example we are using Eclipse IDE along with python plugin to develop gui
from tkinter import *
import tkinter
from tkinter import messagebox
from lib2to3.fixer_util import Number

top = tkinter.Tk()
L1 = Label(top, text="First Number")
L1.pack( side = LEFT)
E1 = Entry(top, bd =5)
E1.pack(side = LEFT)

L2 = Label(top, text="Second Number")
L2.pack( side = LEFT)
E2 = Entry(top, bd =5)
E2.pack(side = LEFT)
def helloCallBack():
a = int(E1.get())
b = int(E2.get())
answer = a + b
#messagebox.showinfo( "Hello Python", "Hello World")
E3.insert(0, answer)
B = tkinter.Button(text ="Add", command = helloCallBack)
B.pack(side = LEFT)
L3 = Label(top, text="Answer")
L3.pack( side = LEFT)
E3 = Entry(top, bd =5)
E3.pack(side = LEFT)


No comments: