Friday, February 12, 2021

day 35 table widget and text widget

from tkinter import * import pymysql def create_table(): conn=pymysql.connect(host="localhost",user="root",password="",db="sslabs") mycursor=conn.cursor() print("inside create table") #mycursor.execute("CREATE TABLE hotel (id INT AUTO_INCREMENT PRIMARY KEY, dosa VARCHAR(255), add VARCHAR(255), idle VARCHAR(255) )") #sql = "INSERT INTO hotel (dosa, idle, add) VALUES (%s, %s, %s)" mycursor.execute("CREATE TABLE hotel (id INT AUTO_INCREMENT PRIMARY KEY, dosa VARCHAR(255),idle VARCHAR(255), sum VARCHAR(255))") #1234514532 #sub=e3.get() #val = (dosa1, idle1) #mycursor.execute(sql, val) conn.commit() print(mycursor.rowcount, "record inserted.") def display(): #create_table() conn=pymysql.connect(host="localhost",user="root",password="",db="sslabs") mycursor=conn.cursor() #print("First Name: %s\nstandard:%s\nsubject:%s" % (e1.get(),e2.get(),e3.get())) #query = "SELECT * FROM student" ## getting records from the table #mycursor.execute(query) ## fetching all records from the 'cursor' object #records = mycursor.fetchall() ## Showing the data #for record in records: #print(record) a=e1.get() a=int(a) print(type(a)) b=e2.get() b=int(b) print(type(b)) sql = "INSERT INTO hotel (dosa, idle,sum) VALUES (%s, %s,%s)" c=a+b #sub=e3.get() val = (a,b,c) mycursor.execute(sql, val) Label(praveen , text=a).grid(row=5) conn.commit() praveen=Tk() #root=Tk() praveen.geometry("500x300") #root.geometry("500x300") praveen.title("Hotel management") #root.title("Hostel management") Label(praveen, text="dosa").grid(row=0) Label(praveen , text="idle").grid(row=1) e1=Entry(praveen) name=e1.grid(row=0,column=1) #e3=Entry(root) #name=e3.grid(row=0,column=1) e2=Entry(praveen) standard = e2.grid(row=1,column=1) Button(praveen,text='Quit', command=praveen.quit).grid(row=2,column=0,sticky=W,pady=4) Button(praveen,text='display', command=display).grid(row=2,column=1,sticky=W,pady=4) #Button(praveen,text='Insert', command=create_table).grid(row=2,column=2,sticky=W,pady=4) mainloop() # -*- coding: utf-8 -*- """ Created on Thu Feb 11 22:45:50 2021 @author: Onyx1 """ from tkinter import * import pymysql root = Tk() # specify size of window. root.geometry("250x170") # Create text widget and specify size. T = Text(root, height = 5, width = 52) T.pack() # Create label l = Label(root, text = "Fact of the Day") l.config(font =("Courier", 14)) l.pack() Fact = """A man can be arrested in Italy for wearing a skirt in public.""" # Create button for next text. b1 = Button(root, text = "Next", ) b1.pack() # Create an Exit button. b2 = Button(root, text = "Exit", command = root.destroy) b2.pack() # Inserroot The Fact. #root.insert(root.END, Fact) root.mainloop()

day 36 menu bar using python

#from tkinter import Toplevel, Button, Tk, Menu ,Label from tkinter import * top = Tk() def display_text(): w = Label(top,text="Hello Tkinter") #new_win=Tk() #new_win.geometry("300*400") w.pack() menubar = Menu(top) file = Menu(menubar, tearoff=0) file.add_command(label="New",command=display_text) file.add_command(label="Open") file.add_command(label="Save") file.add_command(label="Save as...") file.add_separator() file.add_command(label="print") file.add_command(label="print preview") file.add_command(label="Close") 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_command(label="Cut") edit.add_command(label="Copy") edit.add_command(label="Paste") edit.add_separator() 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) view = Menu(menubar, tearoff=0) view.add_command(label="View") menubar.add_cascade(label="View", menu=view) top.config(menu=menubar) top.mainloop()

python class topic video