Python Tutorials

How to Delete Record from Database using PDBC 0

How to Delete Record from Database using PDBC

Program 1 import MySQLdb try: con=MySQLdb.Connect(host=”localhost”,user=”root”,password=”root”,database=”dataflair”) print(“Connection success”) empid=int(input(“Enter employee id for delete: “)) sql = “select * from employee where eid=%d” cur = con.cursor() cur.execute(sql % empid) result = cur.fetchone() if (cur.rowcount ==...

How to Search Records from Database Table using PDBC 0

How to Search Records from Database Table using PDBC

Program 1 import MySQLdb from MySQLdb import * try: con=MySQLdb.Connect(host=”localhost”,user=”root”,password=”root”,database=”dataflair”) print(“Connection Success”) sql=”select * from employee” cur=con.cursor() cur.execute(sql) result=cur.fetchall() print(“—————————————————————-“) print(“ID NAME DEPARTMENT SALARY”) for row in result: print(“%d %s %s %d” %(row[0],row[1],row[2],row[3])) print(“————————————————————-“)...

How to Search One Record from Database Table with PDBC 0

How to Search One Record from Database Table with PDBC

Program 1 import MySQLdb from MySQLdb import * try: con=MySQLdb.Connect(host=”localhost”,user=”root”,password=”root”,database=”dataflair”) print(“Connection Success”) empid=int(input(“Enter Employee id for search:”)) sql=”select * from employee where eid=%d” cur=con.cursor() cur.execute(sql % empid) result=cur.fetchone() if(cur.rowcount==0): print(“——–NO RECORD FOUND—————–“) else: print(“ID...

How to Insert Data in Database Table Using Python Database Connection 0

How to Insert Data in Database Table Using Python Database Connection

Program 1 import MySQLdb from MySQLdb import * try: #Connection con=MySQLdb.Connect(host=”localhost”,user=”root”,password=”root”,database=”dataflair”) print(“Connection Success”) #User Input empid=int(input(“Enter Employee ID:”)) empname=input(“Enter Employee Name:”) empdept=input(“Enter Employee Department:”) empsal = int(input(“Enter Employee Salary:”)) #Query Execution sql=”insert into employee...

Python Program on Database Connection 1

Python Program on Database Connection

Program 1 import MySQLdb from MySQLdb import * try: con=MySQLdb.Connect(host=”localhost”,user=”root”,password=”root”,database=”dataflair”) print(“Connection Success….”) sql=”insert into employee values(115,’hari’,’IT’,8000)” cur=con.cursor() cur.execute(sql) con.commit() print(“Record Inserted……”,cur.rowcount) except Exception as msg: print(msg) finally: con.close() print(“Connection close….”)  

How to Use Input Dialog Window Popup in Python using Tkinter 0

How to Use Input Dialog Window Popup in Python using Tkinter

Program 1 from tkinter import * import tkinter.simpledialog import tkinter.messagebox def btnclick(): name=tkinter.simpledialog.askstring(“Name Box”,”Enter Your Name:”) age=tkinter.simpledialog.askinteger(“Age Box”,”Enter Your Age:”) per=tkinter.simpledialog.askfloat(“Per Box”,”Enter Your Percentages:”) tkinter.messagebox.showinfo(“Result”,”Name is={} Age is={} Per is={}”.format(name,age,per)) myroot=Tk() myroot.geometry(‘600×600’) myroot.title(“Input Dialog...

How to Get a Popup Dialog in Python Tkinter 0

How to Get a Popup Dialog in Python Tkinter

Program 1 from tkinter import * import tkinter.messagebox def btnClick(n): if(n==1): #choice=tkinter.messagebox.askyesnocancel(“Exit Window”,”Are you Sure want to exit…”) #print(choice) choice = tkinter.messagebox.askokcancel(“Exit Window”, “Are you Sure want to exit…”) if(choice==True): myroot.destroy() elif(n==2): tkinter.messagebox.showinfo(“window”,”Record save...

Python Program to Design GUI Applications Using OOPS 0

Python Program to Design GUI Applications Using OOPS

Program 1 from tkinter import * class Myclass: def __init__(self,myroot): self.mf=Frame(myroot,width=500,height=500,bg=’yellow’,cursor=’cross’) self.mf.pack() self.mf.propagate(0) self.btn1=Button(self.mf,width=7,height=2,text=”Red”,bg=’red’,font=(‘Arial,10,bold’),command=lambda :self.myclick(1)) self.btn2 = Button(self.mf, width=7, height=2, text=”Blue”, bg=’blue’, font=(‘Arial,10,bold’),command=lambda :self.myclick(2)) self.btn3 = Button(self.mf, width=7, height=2, text=”Green”, bg=’green’, font=(‘Arial,10,bold’),command=lambda :self.myclick(3)) self.btn1.pack()...

Python Program on Tkinter Checkbutton 0

Python Program on Tkinter Checkbutton

Program 1 from tkinter import * class MyCheck: def __init__(self,myroot): self.mf=Frame(myroot,width=500,height=500,bg=’cyan’) self.mf.pack() self.mf.propagate(0) self.v1=IntVar() self.mychk=Checkbutton(self.mf,text=’RedColor’,variable=self.v1,bg=’cyan’,fg=’red’,font=(‘Algerian’,10,’bold’),command=self.myClick) self.mychk.pack() def myClick(self): #print(self.v1.get()) if(self.v1.get()==1): self.mf[‘bg’]=’red’ if(self.v1.get()==0): self.mf[‘bg’] = ‘cyan’ #Calling Place myroot=Tk() myroot.title(“Checkbox Demo”) myroot.geometry(‘500×500’) myroot.wm_iconbitmap(‘2.ico’) M1=MyCheck(myroot) myroot.mainloop()...

Python Program to Display Images in Tkinter Frames 0

Python Program to Display Images in Tkinter Frames

Program 1 from tkinter import * my_root=Tk() my_root.geometry(‘700×700’) my_root.maxsize(500,500) my_root.minsize(500,500) my_root.title(“My Image Page”) my_root.wm_iconbitmap(‘2.ico’) mf=Frame(my_root,width=’700′,height=’700′,bg=’yellow’,cursor=’cross’) mf.propagate(0) mf.pack() #lb1=Label(mf,width=40,height=2,text=”Enter Student ID:”,bg=’green’,fg=’#EE3B3B’) file1=PhotoImage(file=’bird.gif’) lb1=Label(mf,width=400,height=400,image=file1) lb1.pack() my_root.mainloop()