0% found this document useful (0 votes)
303 views

Program 1: "Name" "Password" "Submit"

The document contains 15 Python programs that demonstrate different Tkinter GUI features: 1. Program 1 creates a listbox widget and adds numbers to it. 2. Program 2 creates a frame widget. 3. Program 3 creates a simple login form using labels and entries. 4. Program 4 creates a similar login form but uses place geometry manager. 5. Program 5 demonstrates creating buttons with different colors and bindings. 6. Program 6 creates two frames side by side.

Uploaded by

soham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
303 views

Program 1: "Name" "Password" "Submit"

The document contains 15 Python programs that demonstrate different Tkinter GUI features: 1. Program 1 creates a listbox widget and adds numbers to it. 2. Program 2 creates a frame widget. 3. Program 3 creates a simple login form using labels and entries. 4. Program 4 creates a similar login form but uses place geometry manager. 5. Program 5 demonstrates creating buttons with different colors and bindings. 6. Program 6 creates two frames side by side.

Uploaded by

soham
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

PROGRAM 1 

from tkinter import * 
root = Tk() 
listbox = Listbox(root) 
listbox.pack() 
for i in range(10): 
    listbox.insert(END, str(i)) 
mainloop() 

PROGRAM 2 
from tkinter import * 
root = Tk() 
root.geometry('100x100') 
Tops = Frame(root, width = 50, height = 50, bd = 10, relief ="raise") 
Tops.pack(side = LEFT) 

PROGRAM 3 
from tkinter import *
parent = Tk()
name = Label(parent,text = "Name").grid(row = 0, column = 0)
e1 = Entry(parent).grid(row = 0, column = 1)
password = Label(parent,text = "Password").grid(row = 1, column = 0)
e2 = Entry(parent).grid(row = 1, column = 1)
submit = Button(parent, text = "Submit").grid(row = 2, column = 1)
parent.mainloop()

PROGRAM 4 
from tkinter import *   
top = Tk()   
top.geometry("250x150")  
name = Label(top, text = "Name").place(x = 10,y = 10)   
email = Label(top, text = "Email").place(x = 10, y = 40)   
password = Label(top, text = "Password").place(x = 10, y = 70)   
e1 = Entry(top).place(x = 95, y = 10)   
e2 = Entry(top).place(x = 95, y = 40)   
e3 = Entry(top).place(x = 95, y = 70)   
top.mainloop() 

PROGRAM 5 
from tkinter import * 
from tkinter import messagebox 
top = Tk()     
top.geometry("200x100")     
def fun():   
    messagebox.showinfo("Hello", "Red Button clicked") 
def fun1():   
    messagebox.showinfo("Hello", "Blue Button clicked") 
def fun2():   
    messagebox.showinfo("Hello", "Green Button clicked") 
def fun3():   
    messagebox.showinfo("Hello", "Yellow Button clicked") 
b1 = Button(top,text = "Red",command = fun,activeforeground = "red",activebackground = 
"pink",pady=10)     
b2 = Button(top, text = "Blue",command = fun1,activeforeground = "blue",activebackground = 
"pink",pady=10)     
b3 = Button(top, text = "Green",command = fun2,activeforeground = "green",activebackground 
= "pink",pady = 10)     
b4 = Button(top, text = "Yellow",command = fun3,activeforeground = "yellow",activebackground 
= "pink",pady = 10)     
b1.pack(side = LEFT)     
b2.pack(side = RIGHT)     
b3.pack(side = TOP)     
b4.pack(side = BOTTOM)     
top.mainloop()   

PROGRAM 6 
from tkinter import *     
top = Tk()   
top.geometry("140x100")   
leftframe = Frame(top,width=50,height=40,bd=5,relief='raise')  
leftframe.pack(side = LEFT)    
rightframe = Frame(top,width=50,height=40,bd=5,relief='raise') 
rightframe.pack(side = RIGHT) 
top.mainloop()   

PROGRAM 7 
import tkinter as tk 
root = tk.Tk() 
sib = tk.Label(root, text='Give em hell Harry', wraplength=12) 
sib.grid() 
root.mainloop() 

PROGRAM 8 
from tkinter import *   
top = Tk() 
top.geometry("200x200")   
checkvar1 = IntVar() 
checkvar2 = IntVar()   
checkvar3 = IntVar() 
chkbtn1 = Checkbutton(top, text = "Python", variable = checkvar1, onvalue = 1, offvalue = 0, 
height = 2, width = 10) 
chkbtn2 = Checkbutton(top, text = "C++", variable = checkvar2, onvalue = 1, offvalue = 0, height 
= 2, width = 10) 
chkbtn3 = Checkbutton(top, text = "Java", variable = checkvar3, onvalue = 1, offvalue = 0, height 
= 2, width = 10) 
chkbtn1.pack() 
chkbtn2.pack() 
chkbtn3.pack() 
top.mainloop() 

PROGRAM 8A 
import tkinter as tk 
class Server(tk.Frame): 
    def __init__(self, master = None): 
        tk.Frame.__init__(self, master) 
        self.grid(sticky = tk.N + tk.S + tk.E + tk.W) 
        self.createWidgets() 

def createWidgets(self): 
        top = self.winfo_toplevel() 
        top.rowconfigure(0, weight = 1) 
        top.columnconfigure(0, weight = 1) 
        self.rowconfigure(0, weight = 1) 
        self.columnconfigure(0, weight = 1) 
        self.quitButton = tk.Button(self, text = "Quit", command = self.quit) 
        self.quitButton.grid(row = 0, column = 0, sticky = tk.N + tk.S) 
        self.newButton = tk.Button(self, text = "New", command = self.makeCheckButtonFlash) 
        self.newButton.grid(row = 0, column = 1, sticky = tk.N + tk.S) 
        self.checkButton = tk.Checkbutton(self, text = "Check Button", activeforeground = "red") 
        self.checkButton.grid(row = 1, column = 0) 

    def makeCheckButtonFlash(self): 
        print ("makeCheckButtonFlash") 
        self.checkButton.deselect() 

app = Server() 
app.master.title("Server") 
app.mainloop() 

PROGRAM 9 
from tkinter import * 
top = Tk() 
top.geometry("120x110") 
var = StringVar() 
msg = Message(top, text = "Welcome to python tkinter",font=('arial',16)) 
msg.pack() 
top.mainloop() 
PROGRAM 10A 
from tkinter import * 
from tkinter import messagebox 
top = Tk() 
top.geometry("100x100") 
messagebox.showinfo("information","Information") 
top.mainloop() 

PROGRAM 10B 
from tkinter import * 
from tkinter import messagebox 
top = Tk() 
top.geometry("100x100") 
messagebox.showwarning("warning","Warning") 
top.mainloop() 

PROGRAM 10C 
from tkinter import * 
from tkinter import messagebox 
top = Tk() 
top.geometry("100x100")   
messagebox.showerror("error","Error") 
top.mainloop() 

PROGRAM 10D 
from tkinter import *   
from tkinter import messagebox     
top = Tk()   
top.geometry("100x100")   
messagebox.askquestion("Confirm","Are you sure?")   
top.mainloop() 

PROGRAM 10E 
from tkinter import *   
from tkinter import messagebox   
top = Tk()   
top.geometry("100x100")   
messagebox.askokcancel("Redirect","Redirecting you to www.google.com")   
top.mainloop() 

PROGRAM 10F 
from tkinter import *   
from tkinter import messagebox   
top = Tk()   
top.geometry("100x100")   
messagebox.askyesno("Application","Got It?")   
top.mainloop() 
 

PROGRAM 10G 
from tkinter import *   
from tkinter import messagebox   
top = Tk()   
top.geometry("100x100")   
messagebox.askretrycancel("Application","try again?")   
top.mainloop() 
 

PROGRAM 11 
from tkinter import * 
top = Tk() 
top.geometry('200x100') 
text = Text(top)   
text.insert(INSERT, "Name.....")   
text.insert(END, "Salary.....")   
text.pack()   
text.tag_add("Write Here", "1.0", "1.4")   
text.tag_add("Click Here", "1.8", "1.13")   
text.tag_config("Write Here", background="yellow", foreground="black")   
text.tag_config("Click Here", background="black", foreground="white")   
top.mainloop() 

PROGRAM 12 
from tkinter import *   
top = Tk()   
sb = Scrollbar(top)   
sb.pack(side = RIGHT, fill = Y)   
mylist = Listbox(top, yscrollcommand = sb.set )   
for line in range(30):   
    mylist.insert(END, "Number " + str(line))   
mylist.pack( side = LEFT )   
sb.config( command = mylist.yview )   
mainloop() 

PROGRAM 13 
from tkinter import *   
def select():   
   sel = "Value = " + str(v.get())   
   label.config(text = sel)   
top = Tk()   
top.geometry("200x100")   
v = DoubleVar()   
scale = Scale( top, variable = v, from_ = 1, to = 50, orient = HORIZONTAL)   
scale.pack(anchor=CENTER)   
btn = Button(top, text="Value", command=select)   
btn.pack(anchor=CENTER)   
label = Label(top)   
label.pack()   
top.mainloop()   

PROGRAM 14 
from tkinter import *   
top = Tk() 
def hello():   
    print("hello!")   
menubar = Menu()   
menubar.add_command(label="Hello!", command=hello)   
menubar.add_command(label="Quit!", command=top.quit)   
top.config(menu=menubar)   
top.mainloop()   

PROGRAM 15 
from tkinter import Toplevel, Button, Tk, Menu   
 
top = Tk()   
menubar = Menu(top)   
file = Menu(menubar, tearoff=0)   
file.add_command(label="New")   
file.add_command(label="Open")   
file.add_command(label="Save")   
file.add_command(label="Save as...")   
file.add_command(label="Close")   
 
file.add_separator()   
file.add_command(label="Exit", command=top.quit) 
menubar.add_cascade(label="File", menu=file) 
edit = Menu(menubar, tearoff=0)   
edit.add_command(label="Undo")   

edit.add_separator() 
edit.add_command(label="Cut") 
edit.add_command(label="Copy") 
edit.add_command(label="Paste") 
edit.add_command(label="Delete") 
edit.add_command(label="Select All")   
menubar.add_cascade(label="Edit", menu=edit)   
help = Menu(menubar, tearoff=0)   
help.add_command(label="About")   
menubar.add_cascade(label="Help", menu=help)   
top.config(menu=menubar) 
top.mainloop() 

You might also like