Jovian
⭐️
Sign In
In [3]:
import tkinter as tk
from tkinter import ttk

class SampleApp(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self._frame = None
        self.switch_frame(StartPage)
        self.geometry("1350x750+0+0")
        self.configure(bg="cadet blue")
    def switch_frame(self,frame_class):
        new_frame=frame_class(self)
        if self._frame is not None:
            self._frame.destroy()
        self._frame=new_frame
        self._frame.pack()
class StartPage(tk.Frame):
    def __init__(self,master):
        tk.Frame.__init__(self,master)
        tk.Label(self,text="Start Page",width=20).pack()
        tk.Button(self,text="Go to page one ",command=lambda: master.switch_frame(PageOne) ).pack(side="left")
        tk.Button(self,text="Go to page two ",command=lambda: master.switch_frame(PageTwo) ).pack()
class PageOne(tk.Frame):
    def __init__(self,master):
        tk.Frame.__init__(self,master)
        tk.Frame.configure(self,bg='blue')
        tk.Label(self,text="page one").grid()
        tk.Button(self,text="Go to start page ",command=lambda: master.switch_frame(StartPage) ).grid()
class PageOne(tk.Frame):
    def __init__ (self,master):
        tk.Frame.__init__(self,master)
        tk.Frame.configure(self,bg='blue')
        tk.Label(self,text="page one").pack()
        tk.Button(self,text="Go to start page ",command=lambda: master.switch_frame(StartPage) ).pack()
class PageTwo(tk.Frame):
    def __init__ (self,master):
        tk.Frame.__init__(self,master)
        tk.Frame.configure(self,bg='red')
        tk.Label(self,text="page two").pack()
        tk.Button(self,text="Go to start page ",command=lambda: master.switch_frame(StartPage) ).pack()
app = SampleApp()
app.mainloop()
        
    
In [6]:
try:
    # Python2
    import Tkinter as tk
except ImportError:
    # Python3
    import tkinter as tk
root = tk.Tk()
root.title('background image')
# pick a .gif image file you have in the working directory
fname = "web.gif"
bg_image = tk.PhotoImage(file=fname)
# get the width and height of the image
w = bg_image.width()
h = bg_image.height()
# size the window so the image will fill it
root.geometry("%dx%d+50+30" % (w, h))
cv = tk.Canvas(width=w, height=h)
cv.pack(side='top', fill='both', expand='yes')
cv.create_image(0, 0, image=bg_image, anchor='nw')
# add canvas text at coordinates x=15, y=20
# anchor='nw' implies upper left corner coordinates
cv.create_text(15, 20, text="Python Greetings", fill="red", anchor='nw')
# now add some button widgets
btn1 = tk.Button(cv, text="Click")
btn1.pack(side='left', padx=10, pady=5, anchor='sw')
btn2 = tk.Button(cv, text="Quit", command=root.destroy)
btn2.pack(side='left', padx=10, pady=5, anchor='sw')
root.mainloop()
In [41]:
import tkinter as tk
from tkinter import*
import sqlite3 as sq

class SampleApp(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self._frame = None
        self.switch_frame(StartPage)
        self.geometry("1600x1000+0+0")
        self.configure(bg="cadet blue")
    def switch_frame(self,frame_class):
        new_frame=frame_class(self)
        if self._frame is not None:
            self._frame.destroy()
        self._frame=new_frame
        self._frame.pack()
class StartPage(tk.Frame):
    def __init__(self,master):
        tk.Frame.__init__(self,master)
        tk.Label(self,text="Studet Database Management",width=30,height=25,bg="green",font=("Vineta BT",20,"bold","italic","underline")).pack()
        tk.Button(self,text="Add Record",command=lambda: master.switch_frame(PageOne) ).place(relx=0.3,rely=0.7,relwidth=0.2)
        tk.Button(self,text="View Record",command=lambda: master.switch_frame(PageTwo) ).place(relx=0.5,rely=0.7,relwidth=0.2)
        tk.Button(self,text="Delete Record",command=lambda: master.switch_frame(PageTwo) ).place(relx=0.3,rely=0.8,relwidth=0.2)
        tk.Button(self,text="Update Record",command=lambda: master.switch_frame(PageTwo) ).place(relx=0.5,rely=0.8,relwidth=0.2)
        tk.Button(self,text="Search record",command=lambda: master.switch_frame(PageTwo) ).place(relx=0.3,rely=0.9,relwidth=0.2)
        tk.Button(self, text="Quit App", command=master.destroy).place(relx=0.5,rely=0.9,relwidth=0.2)
       
        
class PageOne(tk.Frame):
    def __init__ (self,master):
        tk.Frame.__init__(self,master)
        tk.Frame.configure(self,bg='PeachPuff')
        label=tk.Label(self,text=" ",bd=12,width=50,height=15,bg="yellow",fg="blue",font=("times",12,"bold","italic")).pack()
        
        label0=tk.Label(self,text="Add Student Records Here",bg="red",fg="yellow",pady=4,width=50,)
        label0.place(relx=-0.2,rely=0.0)
        label0.config(font=("Vineta BT",10,"bold","italic"))
        
        
        w = Canvas(self,bg="red", width=500, height=100)
        w.pack()
        
        e1 = tk.StringVar(self)
        e2 = tk.StringVar(self)
        e3 = tk.StringVar(self)
        
        
        label1=tk.Label(self,text="Student Name",width=20)
        label1.place(relx=0.1,rely=0.1)
        nentry=tk.Entry(self,textvariable=e1)
        nentry.place(relx=0.5,rely=0.1,relwidth=0.3)
        
        label2=tk.Label(self,text="Father's Name",width=20)
        label2.place(relx=0.1,rely=0.2)
        fentry=tk.Entry(self,textvariable=e2)
        fentry.place(relx=0.5,rely=0.2,relwidth=0.3)
        
        label3=tk.Label(self,text="Age",width=20)
        label3.place(relx=0.1,rely=0.3)
        aentry=tk.Entry(self,textvariable=e3)
        aentry.place(relx=0.5,rely=0.3,relwidth=0.3)
        
        label4=tk.Label(self,text="Gender",width=20)
        label4.place(relx=0.1,rely=0.4)
        
        """"s = tk.IntVar()
        radiobutton1=tk.Radiobutton(self,text="male",value=1,variable=s,command="ShowChoice").place(relx=0.5,rely=0.4)
        radiobutton2=tk.Radiobutton(self,text="Female",value=2,variable=s,command="ShowChoice").place(relx=0.7,rely=0.4)"""
        
      

        con = sq.connect('std.db')
        c = con.cursor()
        comp = tk.StringVar(self)
        comp.set('----')
        
    def get():
        print("You have submitted a record")
        
        c.execute('CREATE TABLE  st (sname TEXT,sfname TEXT,age INTEGER)') 

        c.execute('INSERT INTO st (sname, sfname, age) VALUES (?, ?, ?)',
                  (e1.get(),e2.get(),e3.get())) 
        con.commit()
        
        tk.Button(self,text="Submit",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=get()).place(relx=0.2,rely=0.8,relwidth=0.3)
        tk.Button(self,text="Go to start page ",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda: master.switch_frame(StartPage) ).place(relx=0.5,rely=0.8,relwidth=0.3)


class PageTwo(tk.Frame):
    def __init__ (self,master):
        tk.Frame.__init__(self,master)
        tk.Frame.configure(self,bg='red',height=400,width=600)
        label0=tk.Label(self,text="Student Records View Point",bd=12,width=30,height=1,bg="yellow",fg="blue",font=("Helvetica",12,"bold","italic"))
        label0.place(relx=0.2,rely=0.0)
        
        
        tk.Button(self,text="View Record",bg="ghost white",font=("Helvetica",9,"bold","italic") ).place(relx=0.2,rely=0.8,relwidth=0.3)
        tk.Button(self,text="Go to start page ",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda: master.switch_frame(StartPage) ).place(relx=0.5,rely=0.8,relwidth=0.3)


app = SampleApp()
app.mainloop()
        
    
File "<ipython-input-41-a7f4a8bb1811>", line 79 print("You have submitted a record") ^ IndentationError: expected an indented block
In [28]:
insert_info="INSERT INTO mydb1(username,password) VALUES('shakti','swarup')"
cursor.execute(insert_info)
--------------------------------------------------------------------------- OperationalError Traceback (most recent call last) <ipython-input-28-df36810e66a7> in <module> 1 insert_info="INSERT INTO mydb1(username,password) VALUES('shakti','swarup')" ----> 2 cursor.execute(insert_info) OperationalError: database is locked
In [113]:
import tkinter as tk
from tkinter import ttk
import sqlite3 as sq


root=tk.Tk()
root.title("mySecondApp")
root.geometry("1200x1000")

e1 = tk.StringVar(root)
e2 = tk.StringVar(root)
e3 = tk.StringVar(root)

frame=tk.Frame(root,bg="blue",width=100,height=150)
frame.place(relx=0.2,rely=0.1,relheight=0.5,relwidth=0.5)

label=tk.Label(frame,text="Name",bg="green yellow",width=20)
label.place(relx=0.1,rely=0.1)
entry=tk.Entry(frame,textvariable=e1)
entry.place(relx=0.5,rely=0.1,relwidth=0.3)

label1=tk.Label(frame,text="Age",bg="green yellow",width=20)
label1.place(relx=0.1,rely=0.3)
entry1=tk.Entry(frame,textvariable=e3)
entry1.place(relx=0.5,rely=0.3,relwidth=0.3)

label4=tk.Label(frame,text="weight",bg="green yellow",width=20)
label4.place(relx=0.1,rely=0.2)
entry2=tk.Entry(frame,textvariable=e2)
entry2.place(relx=0.5,rely=0.2,relwidth=0.3)


label3=tk.Label(frame,text="Add record Here!!",bg="red",fg="yellow",pady=4,width=50,)
label3.place(relx=-0.1,rely=0.0)
label3.config(font=("Vineta BT",10,"bold","italic"))

button=tk.Button(frame,text="Submit",activeforeground = "red",activebackground = "pink",pady=2,relief="raised",command=get)
button.place(relx=0.3,rely=0.4,relwidth=0.2)

button1=tk.Button(frame,text="Reset",activeforeground = "red",activebackground = "pink",pady=2,relief="raised",command=root.destroy)
button1.place(relx=0.5,rely=0.4,relwidth=0.2)


con = sq.connect('data.db')
c = con.cursor()
 

def get():
    print("You have submitted a record")
        
    c.execute('CREATE TABLE IF NOT EXISTS stud(name TEXT,weight INTEGER,age INTEGER)') 
    
    c.execute('INSERT INTO stud(name,weight,age) VALUES(?, ?, ?)',e1.get(),e2.get(),e3.get()) 
    con.commit()
    con.close()
        

root.mainloop()


You have submitted a record
In [103]:
import tkinter as tk
from tkinter import*
import sqlite3 as sq

class SampleApp(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self._frame = None
        self.switch_frame(StartPage)
        self.geometry("1600x1000+0+0")
        self.configure(bg="cadet blue")
    def switch_frame(self,frame_class):
        new_frame=frame_class(self)
        if self._frame is not None:
            self._frame.destroy()
        self._frame=new_frame
        self._frame.pack()
class StartPage(tk.Frame):
    def __init__(self,master):
        tk.Frame.__init__(self,master)
        tk.Label(self,text="Studet Database Management",width=30,height=25,bg="green",font=("Vineta BT",20,"bold","italic","underline")).pack()
        tk.Button(self,text="Add Record",command=lambda: master.switch_frame(PageOne) ).place(relx=0.3,rely=0.7,relwidth=0.2)
        tk.Button(self,text="View Record",command=lambda: master.switch_frame(PageTwo) ).place(relx=0.5,rely=0.7,relwidth=0.2)
        tk.Button(self,text="Delete Record",command=lambda: master.switch_frame(PageTwo) ).place(relx=0.3,rely=0.8,relwidth=0.2)
        tk.Button(self,text="Update Record",command=lambda: master.switch_frame(PageTwo) ).place(relx=0.5,rely=0.8,relwidth=0.2)
        tk.Button(self,text="Search record",command=lambda: master.switch_frame(PageTwo) ).place(relx=0.3,rely=0.9,relwidth=0.2)
        tk.Button(self, text="Quit App", command=master.destroy).place(relx=0.5,rely=0.9,relwidth=0.2)
        
    
 
        
class PageOne(tk.Frame):
    def __init__ (self,master):
        tk.Frame.__init__(self,master)
        tk.Frame.configure(self,bg='PeachPuff')
        label=tk.Label(self,text=" ",bd=12,width=50,height=15,bg="yellow",fg="blue",font=("times",12,"bold","italic")).pack()
        
        label0=tk.Label(self,text="Add Student Records Here",bg="red",fg="yellow",pady=4,width=50,)
        label0.place(relx=-0.2,rely=0.0)
        label0.config(font=("Vineta BT",10,"bold","italic"))
        
        
        w = Canvas(self,bg="red", width=500, height=100)
        w.pack()
        
        e1 = tk.StringVar(self)
        e2 = tk.StringVar(self)
        e3 = tk.StringVar(self)
        
        
        label1=tk.Label(self,text="Student Name",width=20)
        label1.place(relx=0.1,rely=0.1)
        nentry=tk.Entry(self,textvariable=e1)
        nentry.place(relx=0.5,rely=0.1,relwidth=0.3)
        
        label2=tk.Label(self,text="Father's Name",width=20)
        label2.place(relx=0.1,rely=0.2)
        fentry=tk.Entry(self,textvariable=e2)
        fentry.place(relx=0.5,rely=0.2,relwidth=0.3)
        
        label3=tk.Label(self,text="Age",width=20)
        label3.place(relx=0.1,rely=0.3)
        aentry=tk.Entry(self,textvariable=e3)
        aentry.place(relx=0.5,rely=0.3,relwidth=0.3)
        
        """" label4=tk.Label(self,text="Gender",width=20)
        label4.place(relx=0.1,rely=0.4)
        
        s = tk.IntVar()
        radiobutton1=tk.Radiobutton(self,text="male",value=1,variable=s,command="ShowChoice").place(relx=0.5,rely=0.4)
        radiobutton2=tk.Radiobutton(self,text="Female",value=2,variable=s,command="ShowChoice").place(relx=0.7,rely=0.4)"""
           
        con = sq.connect('studb.db')
        c = con.cursor()
 

    def get(self):
        print("You have submitted a record")    
        c.execute('CREATE TABLE IF NOT EXISTS stud(name TEXT,fname TEXT,age INTEGER)') 
    
        c.execute('INSERT INTO stud(name,fname,age) VALUES(?, ?, ?)',e1.get(),e2.get(),e3.get()) 
        con.commit()
        con.close()
 
        
        tk.Button(self,text="Submit",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda:addStdRec).place(relx=0.2,rely=0.8,relwidth=0.3)
        tk.Button(self,text="Go to start page ",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda: master.switch_frame(StartPage) ).place(relx=0.5,rely=0.8,relwidth=0.3)
        
        


class PageTwo(tk.Frame):
    def __init__ (self,master):
        tk.Frame.__init__(self,master)
        tk.Frame.configure(self,bg='red',height=400,width=600)
        label0=tk.Label(self,text="Student Records View Point",bd=12,width=30,height=1,bg="yellow",fg="blue",font=("Helvetica",12,"bold","italic"))
        label0.place(relx=0.2,rely=0.0)
#             c.execute('SELECT * FROM stud')
#             record=c.fetchall()
#             print('total rows are',len(record))
#             x=[]
#             for row in record:
#                 x.append(record)
#             df=pd.DataFrame(record)
#             print(df)
#         con = sq.connect('studb.db')
#         c = con.cursor()
        
        tk.Button(self,text="View Record",bg="ghost white",font=("Helvetica",9,"bold","italic") ).place(relx=0.2,rely=0.8,relwidth=0.3)
        tk.Button(self,text="Go to start page ",bg="ghost white",font=("Helvetica",9,"bold","italic"),command=lambda: master.switch_frame(StartPage) ).place(relx=0.5,rely=0.8,relwidth=0.3)


app = SampleApp()
app.mainloop()
In [1]:
from tkinter import *
import sqlite3

root = Tk()
root.geometry('500x500')
root.title("Registration Form")


Fullname=StringVar()
Email=StringVar()
var = IntVar()
c=StringVar()
var1= IntVar()
var2= IntVar()


def database():
    name1=Fullname.get()
    email=Email.get()
    gender=var.get()
    country=c.get()
    prog=var1.get()
    conn = sqlite3.connect('Form.db')
    with conn:
        cursor=conn.cursor()
    cursor.execute('CREATE TABLE IF NOT EXISTS Student (Fullname TEXT,Email TEXT,Gender TEXT,country TEXT,Programming TEXT)')
    cursor.execute('INSERT INTO Student (FullName,Email,Gender,country,Programming) VALUES(?,?,?,?,?)',(name1,email,gender,country,prog,))
    conn.commit()
   
   
             
label_0 = Label(root, text="Registration form",width=20,font=("bold", 20))
label_0.place(x=90,y=53)


label_1 = Label(root, text="FullName",width=20,font=("bold", 10))
label_1.place(x=80,y=130)

entry_1 = Entry(root,textvar=Fullname)
entry_1.place(x=240,y=130)

label_2 = Label(root, text="Email",width=20,font=("bold", 10))
label_2.place(x=68,y=180)

entry_2 = Entry(root,textvar=Email)
entry_2.place(x=240,y=180)

label_3 = Label(root, text="Gender",width=20,font=("bold", 10))
label_3.place(x=70,y=230)

Radiobutton(root, text="Male",padx = 5, variable=var, value=1).place(x=235,y=230)
Radiobutton(root, text="Female",padx = 20, variable=var, value=2).place(x=290,y=230)

label_4 = Label(root, text="country",width=20,font=("bold", 10))
label_4.place(x=70,y=280)

list1 = ['Canada','India','UK','Nepal','Iceland','South Africa'];

droplist=OptionMenu(root,c, *list1)
droplist.config(width=15)
c.set('select your country') 
droplist.place(x=240,y=280)

label_4 = Label(root, text="Programming",width=20,font=("bold", 10))
label_4.place(x=85,y=330)

Checkbutton(root, text="java", variable=var1).place(x=235,y=330)

Checkbutton(root, text="python", variable=var2).place(x=290,y=330)

Button(root, text='Submit',width=20,bg='brown',fg='white',command=database).place(x=180,y=380)

root.mainloop()
In [2]:
import tkinter as Tk
OPTIONS = [
    "egg",
    "bunny",
    "chicken"
]

master = Tk()

variable = StringVar(master)
variable.set(OPTIONS[0]) # default value

w = apply(OptionMenu, (master, variable) + tuple(OPTIONS))
w.pack()

mainloop()
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-2-cce05dc30a14> in <module> 6 ] 7 ----> 8 master = Tk() 9 10 variable = StringVar(master) TypeError: 'module' object is not callable
In [1]:
#sirs project
from tkinter import * #GUI package
import sqlite3 as sq #For tables and database
import datetime

window = Tk()
window.title("Compound Tracker") 
window.geometry('800x600+0+0')
header = Label(window, text="Compound Tracker for Weightlifting", font=("arial",30,"bold"), fg="steelblue").pack()

con = sq.connect('Gym.db') #dB browser for sqlite needed
c = con.cursor() #SQLite command, to connect to db so 'execute' method can be called


L1 = Label(window, text = "Compound Lift", font=("arial", 18)).place(x=10,y=100)
L2 = Label(window, text = "Day (dd)", font=("arial",18)).place(x=10,y=150)
L3 = Label(window, text = "Month (mm)", font=("arial",18)).place(x=10,y=200)
L4 = Label(window, text = "Year (yyyy)", font=("arial",18)).place(x=10,y=250)
L5 = Label(window, text = "Max Weight (KG)", font=("arial",18)).place(x=10,y=300)
L6 = Label(window, text = "Reps", font=("arial",18)).place(x=10,y=350)

#Create variables for each list
comp = StringVar(window)#For 1st dd
comp.set('----') #Inital placeholder for field

compdb = StringVar(window)#2nd dropdown list
compdb.set('----')

day = StringVar(window)
month = StringVar(window)
year = StringVar(window)
weight = StringVar(window)
reps = StringVar(window)

#Dictionary for drop down list
compound = {'Bench', 'Squat', 'Deadlift','OVH'}

compd = OptionMenu(window, comp, *compound) #For 1st drop down list 
compd.place(x=220,y=105)

compdbase = OptionMenu(window, compdb, *compound)#For 2nd drop down list
compdbase.place(x=100,y=500)

#Entry for 'input' in GUI
dayT = Entry(window, textvariable=day)
dayT.place(x=220,y=155)

monthT = Entry(window, textvariable=month)
monthT.place(x=220,y=205)

yearT = Entry(window, textvariable=year)
yearT.place(x=220,y=255)

weightT = Entry(window, textvariable=weight)
weightT.place(x=220,y=305)

repT = Entry(window, textvariable=reps)
repT.place(x=220,y=355)

#get func to isolate the text entered in the entry boxes and submit to database
def get():
        print("You have submitted a record")
        
        c.execute('CREATE TABLE IF NOT EXISTS ' +comp.get()+ ' (Datestamp TEXT, MaxWeight INTEGER, Reps INTEGER)') #SQL syntax
        
        date = datetime.date(int(year.get()),int(month.get()), int(day.get())) #Date in format from 'import datetime'

        c.execute('INSERT INTO ' +comp.get()+ ' (Datestamp, MaxWeight, Reps) VALUES (?, ?, ?)',
                  (date, weight.get(), reps.get())) #Insert record into database.
        con.commit()

#Reset fields after submit
        comp.set('----')
        day.set('')
        month.set('')
        year.set('')
        weight.set('')
        reps.set('')

#Clear boxes when submit button is hit
def clear():
    comp.set('----')
    compdb.set('----')
    day.set('')
    month.set('')
    year.set('')
    weight.set('')
    reps.set('')
    
def record():
    c.execute('SELECT * FROM  ') #Select from which ever compound lift is selected

    frame = Frame(window)
    frame.place(x= 400, y = 150)
    
    Lb = Listbox(frame, height = 8, width = 25,font=("arial", 12)) 
    Lb.pack(side = LEFT, fill = Y)
    
    scroll = Scrollbar(frame, orient = VERTICAL) # set scrollbar to list box for when entries exceed size of list box
    scroll.config(command = Lb.yview)
    scroll.pack(side = RIGHT, fill = Y)
    Lb.config(yscrollcommand = scroll.set) 
    

    Lb.insert(0, 'Date, Max Weight, Reps') #first row in listbox
    
    data = c.fetchall() # Gets the data from the table
    
    for row in data:
        Lb.insert(1,row) # Inserts record row by row in list box

    L7 = Label(window, text = compdb.get()+ '      ', 
               font=("arial", 16)).place(x=400,y=100) # Title of list box, given which compound lift is chosen

    L8 = Label(window, text = "They are ordered from most recent", 
               font=("arial", 16)).place(x=400,y=350)
    con.commit()

button_1 = Button(window, text="Submit",command=get)
button_1.place(x=100,y=400)

button_2 = Button(window,text= "Clear",command=clear)
button_2.place(x=10,y=400)

button_3 = Button(window,text="Open DB",command=record)
button_3.place(x=10,y=500)


window.mainloop()
In [1]:
import jovian
In [ ]:
jovian.commit()
[jovian] Saving notebook..
In [ ]: