Related
I am new to Python and would like to implement a simple Employee Management System (as shown on the attached photo) that do the following functionality
• A GUI for entering, viewing, and exporting employee data. (I have done this task)
• The ability to export data into an Excel or csv file. (I have done this task)
• The ability to import data from an Excel or csv file into the GUI.
• The ability to edit employee data on screen and save the updated result to a file
I need to implement the last two tasks (i.e., import data from an CSV file and display on the GUI Window rather than on the Python Console) as my current code load the CSV file content into the Python console .
Moreover, I would like to edit the employee data on the GUI screen and save the updated result to the csv file.
Here is my code
from csv import *
from tkinter import *
from tkinter import filedialog
import tkinter.messagebox
root = Tk()
root.title("Employee Management System")
root.geometry("700x350")
root.maxsize(width=700, height=350)
root.minsize(width=700, height=350)
root.configure(background="dark gray")
# Define Variables
main_lst=[]
def OpenFile():
filepath=filedialog.askopenfilename()
# print(filepath)
# OR
file=open(filepath,'r')
print(file.read())
file.close
def Add():
lst=[txtFullname.get(),txtAddress.get(),txtAge.get(),txtPhoneNumber.get(),txtGender.get()]
main_lst.append(lst)
messagebox.showinfo("Information","The data has been added successfully")
def Save():
with open("data_entry.csv","w") as file:
Writer=writer(file)
Writer.writerow(["txtFullname","txtAddress","txtAge","txtPhoneNumber","txtGender"])
Writer.writerows(main_lst)
messagebox.showinfo("Information","Saved succesfully")
def Clear():
txtFullname.delete(0,END)
txtAddress.delete(0,END)
txtAge.delete(0,END)
txtPhoneNumber.delete(0,END)
txtGender.delete(0,END)
def Exit():
wayOut = tkinter.messagebox.askyesno("Employee Management System", "Do you want to exit the
system")
if wayOut > 0:
root.destroy()
return
# Label Widget
labelFN = Label( root,text="Full Name", font=('arial', 12, 'bold'), bd=10, fg="white",
bg="dark blue").grid(row=1, column=0)
labelAdd = Label(root, text="Home Address", font=('arial', 12, 'bold'), bd=10, fg="white",
bg="dark blue").grid(row=2, column=0)
labelAge = Label( root,text="Age", font=('arial', 12, 'bold'), bd=10, fg="white", bg="dark
blue").grid(row=3, column=0)
labelPhone_Num = Label( root, text="Phone Number", font=('arial', 12, 'bold'), bd=10,
fg="white", bg="dark blue").grid(row=4, column=0)
labelGender = Label( text="Gender", font=('arial', 12, 'bold'), bd=10, fg="white", bg="dark
blue").grid(row=5, column=0)
# Entry Widget
txtFullname = Entry(root, font=('arial', 12, 'bold'), bd=4, width=22, justify='left')
txtFullname.grid(row=1, column=1)
txtAddress = Entry(root, font=('arial', 12, 'bold'), bd=4, width=22, justify='left')
txtAddress.grid(row=2, column=1)
txtAge = Entry(root, font=('arial', 12, 'bold'), bd=4, width=22, justify='left')
txtAge.grid(row=3, column=1)
txtPhoneNumber = Entry(root, font=('arial', 12, 'bold'), bd=4, width=22, justify='left')
txtPhoneNumber.grid(row=4, column=1)
txtGender = Entry(root, font=('arial', 12, 'bold'), bd=4, width=22, justify='left')
txtGender.grid(row=5, column=1)
# Buttons
ButtonLoad = Button(text='LoadFile', padx=10, pady=8, bd=4, font=('arial', 12, 'bold'),
width=8, fg="black",bg="dark gray", command=OpenFile).grid(row=6, column=0)
ButtonAdd = Button( text='Add Record', padx=10, pady=8, bd=4, font=('arial', 12, 'bold'),
width=8, fg="black", bg="dark gray", command=Add).grid(row=6, column=1)
ButtonSave = Button(text='Save', padx=10, pady=8, bd=4, font=('arial', 12, 'bold'), width=8,
fg="black", bg="dark gray", command=Save).grid(row=6, column=2)
ButtonClear = Button(text='Clear', padx=10, pady=8, bd=4, font=('arial', 12, 'bold'), width=8,
fg="black", bg="dark gray", command=Clear).grid(row=6, column=3)
ButtonExit = Button(text='Exit', padx=10, pady=8, bd=4, font=('arial', 12, 'bold'), width=8,
fg="black",bg="dark gray", command=Exit).grid(row=6, column=4)
'''
ButtonImport = Button(text='Import', padx=10, pady=8, bd=4, font=('arial', 12, 'bold'),
width=8, fg="black",bg="dark gray", command=Import).grid(row=6, column=5)
'''
root.mainloop()
Employee Management System-Screenshot of the current output
In order to import data from a csv file you can use the reader method from the csv module and simply load that information into your main_lst list through your OpenFile function. I am not sure about editing though since your UI can only show one entry at a time, it makes it difficult to know which entry you are trying to edit.
from csv import *
from tkinter import *
from tkinter import filedialog
from tkinter import messagebox
root = Tk()
root.title("Employee Management System")
root.geometry("700x350")
root.maxsize(width=700, height=350)
root.minsize(width=700, height=350)
root.configure(background="dark gray")
# Define Variables
main_lst=[]
def OpenFile():
filepath=filedialog.askopenfilename()
with open(filepath, "rt") as csvfile:
rows = reader(csvfile)
for row in rows:
main_lst.append(row)
lst = [txtFullname, txtAddress, txtAge, txtPhoneNumber, txtGender]
for i,x in enumerate(lst):
x.insert(0, row[i])
def Add():
lst=[txtFullname.get(),txtAddress.get(),txtAge.get(),txtPhoneNumber.get(),txtGender.get()]
main_lst.append(lst)
messagebox.showinfo("Information","The data has been added successfully")
def Save():
with open("data_entry.csv","w") as file:
Writer=writer(file)
Writer.writerow(["txtFullname","txtAddress","txtAge","txtPhoneNumber","txtGender"])
Writer.writerows(main_lst)
messagebox.showinfo("Information","Saved succesfully")
def Clear():
txtFullname.delete(0,END)
txtAddress.delete(0,END)
txtAge.delete(0,END)
txtPhoneNumber.delete(0,END)
txtGender.delete(0,END)
def Exit():
wayOut = messagebox.askyesno("Employee Management System", "Do you want to exit the system")
if wayOut > 0:
root.destroy()
return
# Label Widget
labelFN = Label( root,text="Full Name", font=('arial', 12, 'bold'), bd=10, fg="white", bg="dark blue").grid(row=1, column=0)
labelAdd = Label(root, text="Home Address", font=('arial', 12, 'bold'), bd=10, fg="white", bg="dark blue").grid(row=2, column=0)
labelAge = Label( root,text="Age", font=('arial', 12, 'bold'), bd=10, fg="white", bg="dark blue").grid(row=3, column=0)
labelPhone_Num = Label( root, text="Phone Number", font=('arial', 12, 'bold'), bd=10, fg="white", bg="dark blue").grid(row=4, column=0)
labelGender = Label( text="Gender", font=('arial', 12, 'bold'), bd=10, fg="white", bg="dark blue").grid(row=5, column=0)
# Entry Widget
txtFullname = Entry(root, font=('arial', 12, 'bold'), bd=4, width=22, justify='left')
txtFullname.grid(row=1, column=1)
txtAddress = Entry(root, font=('arial', 12, 'bold'), bd=4, width=22, justify='left')
txtAddress.grid(row=2, column=1)
txtAge = Entry(root, font=('arial', 12, 'bold'), bd=4, width=22, justify='left')
txtAge.grid(row=3, column=1)
txtPhoneNumber = Entry(root, font=('arial', 12, 'bold'), bd=4, width=22, justify='left')
txtPhoneNumber.grid(row=4, column=1)
txtGender = Entry(root, font=('arial', 12, 'bold'), bd=4, width=22, justify='left')
txtGender.grid(row=5, column=1)
# Buttons
ButtonLoad = Button(text='LoadFile', padx=10, pady=8, bd=4, font=('arial', 12, 'bold'), width=8, fg="black",bg="dark gray", command=OpenFile).grid(row=6, column=0)
ButtonAdd = Button( text='Add Record', padx=10, pady=8, bd=4, font=('arial', 12, 'bold'), width=8, fg="black", bg="dark gray", command=Add).grid(row=6, column=1)
ButtonSave = Button(text='Save', padx=10, pady=8, bd=4, font=('arial', 12, 'bold'), width=8, fg="black", bg="dark gray", command=Save).grid(row=6, column=2)
ButtonClear = Button(text='Clear', padx=10, pady=8, bd=4, font=('arial', 12, 'bold'), width=8, fg="black", bg="dark gray", command=Clear).grid(row=6, column=3)
ButtonExit = Button(text='Exit', padx=10, pady=8, bd=4, font=('arial', 12, 'bold'), width=8, fg="black",bg="dark gray", command=Exit).grid(row=6, column=4)
'''
ButtonImport = Button(text='Import', padx=10, pady=8, bd=4, font=('arial', 12, 'bold'),
width=8, fg="black",bg="dark gray", command=Import).grid(row=6, column=5)
'''
root.mainloop()
your csv file should look like this:
example.csv
txtFullname,txtAddress,txtAge,txtPhoneNumber,txtGender
Bob,Main St.,35,18004438768,Male
Alice,1st St.,62,922-333-1253,Female
I am making an app that would calculate area, tsa, lsa, volume, etc. for various shapes
but I am getting this error:
NameError: name 'Square_Area' is not defined
but the function is exactly named same as the one in the line
I am so confused
this is the bit of code that is getting error
# layout for area of square
tsaf = Frame(root)
saf = Frame(root)
Label(tsaf, bg="gray", fg="blue", text="Square Area Calculator",
font=("calibri", 18, "italic")).pack(fill="x", ipady=10)
Label(saf, fg="red", text="Side of Square:",
font=("calibri", 18, "italic")).grid(row=0, column=0, pady=30, padx=30)
Label(saf, fg="red", text="Area of Square:",
font=("calibri", 18, "italic")).grid(row=1, column=0, pady=30, padx=30)
Entry(saf, fg="blue", borderwidth=6, textvariable=SquareSide,
font=("comicsansms", 16, "bold")).grid(row=0, column=1, pady=30, padx=20, ipadx=50)
Entry(saf, fg="blue", borderwidth=6, textvariable=SquareArea,
font=("comicsansms", 16, "bold")).grid(row=1, column=1, pady=30, padx=20, ipadx=50)
Button(saf, fg="blue", text="Get Area", activeforeground="red", borderwidth=4, command =
Square_Area,
font=("comicsansms", 16, "italic")).grid(row=2, column=1, pady=30, padx=50, ipadx=50)
and this is the function the button is using
def Square_Area():
side = float(SquareSide.get())
area = side*side
SquareArea.set(f"{area}")
I have tried everything on my side if anyone can pls help
if you need the full code I am listing it below
i will remove the unnecessary part
from tkinter import *
root = Tk()
# setting up window
root.geometry("600x400")
root.minsize(600, 400)
root.maxsize(600, 400)
root.title("Shape Calculator")
# declaring variable
SquareSide = StringVar()
SquareArea = StringVar()
# main page text
mt = Frame(root)
mt.pack()
title = Label(mt, fg="red", text="Select any field that you want to calculate",
font=("arial", 18, "bold"))
title.pack(padx=62, pady=185, side=LEFT)
# layout for area of square
tsaf = Frame(root)
saf = Frame(root)
Label(tsaf, bg="gray", fg="blue", text="Square Area Calculator",
font=("calibri", 18, "italic")).pack(fill="x", ipady=10)
Label(saf, fg="red", text="Side of Square:",
font=("calibri", 18, "italic")).grid(row=0, column=0, pady=30, padx=30)
Label(saf, fg="red", text="Area of Square:",
font=("calibri", 18, "italic")).grid(row=1, column=0, pady=30, padx=30)
Entry(saf, fg="blue", borderwidth=6, textvariable=SquareSide,
font=("comicsansms", 16, "bold")).grid(row=0, column=1, pady=30, padx=20, ipadx=50)
Entry(saf, fg="blue", borderwidth=6, textvariable=SquareArea,
font=("comicsansms", 16, "bold")).grid(row=1, column=1, pady=30, padx=20, ipadx=50)
Button(saf, fg="blue", text="Get Area", activeforeground="red", borderwidth=4, command =
Square_Area,
font=("comicsansms", 16, "italic")).grid(row=2, column=1, pady=30, padx=50, ipadx=50)
# menu functions
# area functions
def square_area():
kill_frame()
tsaf.pack(fill="both")
saf.pack(side=LEFT, anchor="nw")
# function to clear screen
def kill_frame():
mt.pack_forget()
saf.pack_forget()
tsaf.pack_forget()
# getting results
# area result functions
def Square_Area():
side = float(SquareSide.get())
area = side*side
SquareArea.set(f"{area}")
# making the menu
main_menu = Menu(root)
# 2d shape area
m1 = Menu(main_menu, tearoff=0)
m1.add_command(label="Square", command = square_area)
main_menu.add_cascade(label="Area calculator", menu=m1)
root.config(menu=main_menu)
root.mainloop()
i have removed everything about other shapes and just left the square part
sorry if its a bit messy
You need to define the function before you reference it. Since you are not using classes, you are doing procedural programming where python executes from top to bottom. You are referencing the function which is defined later, thus giving an error.
Define the function square_area anywhere before you reference it.
So you can do this:
from tkinter import *
root = Tk()
# setting up window
root.geometry("600x400")
root.minsize(600, 400)
root.maxsize(600, 400)
root.title("Shape Calculator")
# declaring variable
SquareSide = StringVar()
SquareArea = StringVar()
def square_area():
kill_frame()
tsaf.pack(fill="both")
saf.pack(side=LEFT, anchor="nw")
def Square_Area():
side = float(SquareSide.get())
area = side*side
SquareArea.set(f"{area}")
# main page text
mt = Frame(root)
mt.pack()
title = Label(mt, fg="red", text="Select any field that you want to calculate",
font=("arial", 18, "bold"))
title.pack(padx=62, pady=185, side=LEFT)
# layout for area of square
tsaf = Frame(root)
saf = Frame(root)
Label(tsaf, bg="gray", fg="blue", text="Square Area Calculator",
font=("calibri", 18, "italic")).pack(fill="x", ipady=10)
Label(saf, fg="red", text="Side of Square:",
font=("calibri", 18, "italic")).grid(row=0, column=0, pady=30, padx=30)
Label(saf, fg="red", text="Area of Square:",
font=("calibri", 18, "italic")).grid(row=1, column=0, pady=30, padx=30)
Entry(saf, fg="blue", borderwidth=6, textvariable=SquareSide,
font=("comicsansms", 16, "bold")).grid(row=0, column=1, pady=30, padx=20, ipadx=50)
Entry(saf, fg="blue", borderwidth=6, textvariable=SquareArea,
font=("comicsansms", 16, "bold")).grid(row=1, column=1, pady=30, padx=20, ipadx=50)
Button(saf, fg="blue", text="Get Area", activeforeground="red", borderwidth=4, command =
square_area,
font=("comicsansms", 16, "italic")).grid(row=2, column=1, pady=30, padx=50, ipadx=50)
# menu functions
# area functions
# function to clear screen
def kill_frame():
mt.pack_forget()
saf.pack_forget()
tsaf.pack_forget()
# getting results
# area result functions
# making the menu
main_menu = Menu(root)
# 2d shape area
m1 = Menu(main_menu, tearoff=0)
m1.add_command(label="Square", command = square_area)
main_menu.add_cascade(label="Area calculator", menu=m1)
root.config(menu=main_menu)
root.mainloop()
no error shown, i just removed the scrollbar command previously added as it wasnt working. i hope someone will be able to advise how to do this as i had gone thru multiple tutorials even those advises in stack overflow. i need to be able to scroll thru the entire window, below is the full code as requested.
import tkinter as tk
from tkinter import *
import time;
import datetime
from tkinter import ttk
from PIL import ImageTk, Image
import os
root = Tk()
root.title("Fibroscan Report")
root.geometry("1000x1200")
root.iconbitmap('d:/python_file/python_gui/zaclogo.ico')
frame0 = Frame(root, width=200, height=100)
frame0.pack()
frame0.pack_propagate(0)
frame1 = Frame(frame0, width=200, height=110, padx= 5, pady=5, bd=10,relief=RIDGE)
frame1.grid(row=0, column=0)
frame2 = Frame (frame0, width=200, padx= 5, pady=5, bd=10, relief= RIDGE)
frame2.grid(row=0, column=1)
frame3 = Frame(root, width=400, height=100)
frame3.pack()
frame3.pack_propagate(0)
frame4 = Frame(frame3, width=600, height=50, padx= 5, pady=5, bd=10, relief=RIDGE)
frame4.grid(row=0, column=0)
frame4.grid_propagate(0)
frame = Frame (root, width=200, height=100, padx=5, pady=15, relief=RIDGE)
frame.pack()
frame.pack_propagate(0)
framephoto = Frame (frame)
framephoto.grid()
canvas = Canvas(framephoto, width = 800, height = 324)
canvas.grid()
img = ImageTk.PhotoImage(Image.open("metavirchart2.png"))
canvas.create_image(107, 0, anchor=NW, image=img)
canvas.image = img
frame5 = LabelFrame (root,text="Fibroscan® Score Guide",font=('arial', 10), padx= 5, pady=5, bd=10, relief= RIDGE)
frame5.pack()
frame5.pack_propagate(0)
frame6 = Frame (frame5, width=230, height=50, padx= 5, pady=5, bd=10, relief= RIDGE)
frame6.grid(row=1, column=0)
frame6.grid_propagate(0)
frame7 = Frame (frame5, width=230, height=115, padx= 5, pady=5, bd=10, relief= RIDGE)
frame7.grid(row=2, column=0)
frame7.grid_propagate(0)
frame8 = Frame (frame5, width=230, height=50, padx= 5, pady=5, bd=10, relief= RIDGE)
frame8.grid(row=3, column=0)
frame8.grid_propagate(0)
frame9 = Frame (frame5, width=230, height=100, padx= 5, pady=5, bd=10, relief= RIDGE)
frame9.grid(row=4, column=0)
frame9.grid_propagate(0)
frame10 = Frame (frame5, width=515, height=50, padx= 5, pady=5, bd=10, relief= RIDGE)
frame10.grid(row=1, column=1)
frame10.grid_propagate(0)
frame11 = Frame (frame5, width=515, height=115, padx= 5, pady=5, bd=10, relief= RIDGE)
frame11.grid(row=2, column=1)
frame11.grid_propagate(0)
frame12 = Frame (frame5, width=515, height=50, padx= 5, pady=5, bd=10, relief= RIDGE)
frame12.grid(row=3, column=1)
frame12.grid_propagate(0)
frame13 = Frame (frame5, width=515, height=100, padx= 5, pady=5, bd=10, relief= RIDGE)
frame13.grid(row=4, column=1)
frame13.grid_propagate(0)
frameguide = Frame (frame5)
frameguide.grid(row=0, column=0)
frameguide.grid_propagate(0)
frame14 = Frame (frame13)
frame14.grid(row=0, column=1)
frame14.grid_propagate(0)
identity = StringVar()
fullname = StringVar()
refdr = StringVar(root)
datescan = StringVar()
dob = StringVar()
operator = StringVar()
operator.set('Insert Operator Name')
kpa = IntVar()
metavir = StringVar()
idrtype = StringVar()
idrtxt = StringVar()
lblidentity = Label(frame1, text="Patient ID", font=('arial', 10, 'bold'))
lblidentity.grid(row=0, column=0, sticky=W)
txtidentity = Entry(frame1, width=24, textvariable=identity, font=('arial', 10))
txtidentity.grid(row=0, column=1)
lblfullname = Label(frame1, text="Patient Name", font=('arial', 10, 'bold'))
lblfullname.grid(row=1, column=0, sticky=W)
txtfullname = Entry(frame1, width=24, textvariable=fullname, font=('arial', 10))
txtfullname.grid(row=1, column=1)
lbldob = Label(frame1, text="Date of Birth", font=('arial', 10, 'bold'))
lbldob.grid(row=2, column=0, sticky=W)
txtdob = Entry(frame1, width=24,textvariable=dob, font=('arial', 10))
txtdob.grid(row=2, column=1)
lblrefdr = Label(frame1, text="Referring Doctor", font=('arial', 10, 'bold'))
lblrefdr.grid(row=3, column=0, sticky=W)
txtrefdr = ttk.Combobox(frame1, width=24,
values=[
"Operator1",
"Operator2",
"Operator3",
"Operator4",
"Operator5",
"Operator6",
"Operator7"], state = "readonly")
txtrefdr.grid(row=3, column=1)
txtrefdr.current(0)
lbldatescan = Label(frame2, text="Date of Scan", font=('arial', 10, 'bold'))
lbldatescan.grid(row=0, column=0, sticky=W)
txtdatescan = Entry(frame2, width=24, textvariable=datescan, font=('arial', 10))
txtdatescan.grid(row=0, column=1)
lblindi = Label(frame2, text="Indication", font=('arial', 10, 'bold'))
lblindi.grid(row=1, column=0, sticky=W)
txtindi = ttk.Combobox(frame2,width=24,
values=[
"Hepatitis B*",
"HCV-HIV co-infection*",
"Hepatitis C",
"Hepatitis C*",
"Chronic Cholestatic Diseases*",
"Alcohol**",
"Others",
"NAFLD***"], state="readonly")
txtindi.grid(row=1, column=1)
txtindi.current(0)
lblgender = Label(frame2, text="Gender", font=('arial', 10, 'bold'))
lblgender.grid(row=2, column=0, sticky=W)
gender = ["Male", "Female", "Unspecified"]
txtgender = ttk.Combobox(frame2, width=24,
values=gender, state="readonly")
txtgender.grid(row=2, column=1)
txtgender.current(0)
lblop = Label(frame2, text="Operator", font=('arial', 10, 'bold'))
lblop.grid(row=3, column=0, sticky=W)
txtop = Entry(frame2, width=24, textvariable=operator, font=('arial', 10))
txtop.grid(row=3, column=1)
lbltitle = Label(frame4, text="YOUR FIBROSCAN® SCORE (Median LSM) is: ")
lbltitle.grid(row=0, column=0)
lblkpa = Label(frame4, text="KPa ")
lblkpa.grid(row=0, column=2)
txtkpa = Entry(frame4, textvariable=kpa, font=('arial', 10), width=5)
txtkpa.grid(row=0, column=1)
lblmeta = Label(frame4, text=" Metavir Stage: ")
lblmeta.grid(row=0, column=3)
metavir_score = ["F0", "F0-F1", "F1", "F1-F2", "F2", "F2-F3", "F3-F4", "F4"]
txtmeta = ttk.Combobox(frame4, width=10,
values=metavir_score, textvariable=metavir, state="readonly")
txtmeta.grid(row=0, column=4)
txtmeta.current(0)
lbltitle2 = Label(frame6,
text="Underlying Liver Disease", font=('arial', 10, 'bold'))
lbltitle2.grid(sticky=E)
lbltitle3 = Label(frame7,
text="Assessment", font=('arial', 10, 'bold'))
lbltitle3.grid(sticky=W)
lbltitle4 = Label(frame8,
text="Clinical Interpretation", font=('arial', 10, 'bold'))
lbltitle4.grid(sticky=W)
lbltitle5 = Label(frame9,
text="Recommended Clinical Actions", font=('arial', 10, 'bold'))
lbltitle5.grid(sticky=W)
lbltitleudl = Label(frame10,
text="next to UDL", font=('arial', 10, 'bold'))
lbltitleudl.grid()
lbltitle3a = Label(frame11,
text="Fibroscan Median LSM =", font=('arial', 10, 'bold'))
lbltitle3a.grid(row=0, column=0, sticky =W)
txtitle3a = Entry(frame11, width=16)
txtitle3a.grid(row=0, column=1)
lbltitle3a = Label(frame11,
text="Metavir Stage =", font=('arial', 10, 'bold'))
lbltitle3a.grid(row=1, column=0, sticky=W)
txtmetasg = ttk.Combobox(frame11, width=13,
values=metavir_score, state="readonly")
txtmetasg.grid(row=1, column=1)
txtmetasg.current(0)
lbltitle3a = Label(frame11,
text="Probe Type =", font=('arial', 10, 'bold'))
lbltitle3a.grid(row=2, column=0, sticky=W)
txtmeta = ttk.Combobox(frame11, width=13,
values=[
"S",
"M",
"XL",
"Others"], state="readonly")
txtmeta.grid(row=2, column=1)
txtmeta.current(0)
lbltitle3a = Label(frame11,
text="IQR/Median =", font=('arial', 10, 'bold'))
lbltitle3a.grid(row=3, column=0, sticky=W)
txtitle3a = Entry(frame11, width=16, textvariable=idrtype)
txtitle3a.grid(row=3, column=1)
lbltitle3a = Label(frame12,
text="Significant Fibrosis =", font=('arial', 13, 'bold'))
lbltitle3a.grid(row=0, column= 0)
txtmeta = ttk.Combobox(frame12, width=10,
values=[
"Yes",
"No"], state="readonly")
txtmeta.grid(row=0, column=1)
txtmeta.current(0)
fcolumn = Frame(frame13)
fcolumn.grid()
fcolumn1 = Frame(frame13)
fcolumn1.grid(sticky=W)
txtrca = ttk.Combobox(fcolumn, width=77, height=200,
values=[
"Repeat Fibroscan in 1 year",
"Patients with significant liver fibrosis have an increased risk of complications secondary \n to liver disease and development of HCC and should be considered \n for treatment of underlying aetiology or risk factor modification.",
"In patients with advanced fibrosis or cirrhosis, regular screening \n and surveillance for HCC is also recommended.",
])
txtrca.grid(row=0, column=0)
txtrca.current(0)
txtrca.grid_propagate(0)
lbliqr = Label(fcolumn1,
text="M Probe IQR/MEDIAN =", font=('arial', 10, 'bold'))
lbliqr.grid(row=1, column=0, sticky =W)
txtiqr = Entry(fcolumn1, width=16, textvariable=idrtxt)
txtiqr.grid(row=1, column=1)
lblguide = Label(fcolumn1,
text="*AASLD, APASL, EASL Guidelines", font=('arial', 10, 'bold'))
lblguide.grid(row=2, column=0, sticky =W)
root.mainloop()
any help will be appreciated.
no hate comments pls if u cant help or dun wish to help.
Try this
from tkinter import *
scroll_bar = Scrollbar(root)
scroll_bar.pack(side=RIGHT,fill=Y)
def square():
def calculate():
global area
global perimeter
side = entry_variable.get()
area = side * side
area_variable.set(area)
perimeter = 4 * side
perimeter_variable.set(perimeter)
root = Tk()
root.minsize(width=400, height=400)
root.maxsize(width=400, height=400)
root.config(bg="Black")
entry_variable = IntVar()
area_variable = IntVar()
perimeter_variable = IntVar()
label1 = Label(root, text="", font=('Arial', 15, 'bold'), fg="white", bg='Black')
label1.grid()
label0 = Label(root, text="Enter the Side's measurement", font=('Arial', 15, 'bold'), fg="white", bg='Black')
label0.grid(row=1)
label00 = Label(root, text="", font=('Arial', 15, 'bold'), fg="white", bg='Black')
label00.grid(row=3)
entry1 = Entry(root, font=('Arial', 15, 'bold'), justify=RIGHT, textvariable=entry_variable, fg='black')
entry1.grid(row=2)
label2 = Label(root, text="Perimeter of the Square", font=('Arial', 15, 'bold'), fg="white", bg='Black')
label2.grid(row=5)
label3 = Label(root, text="Area of the Square", font=('Arial', 15, 'bold'), fg="white", bg='Black')
label3.grid(row=7)
entry2 = Entry(root, font=('Arial', 15, 'bold'), fg='black', justify=RIGHT, textvariable=perimeter_variable,
state='disabled')
entry2.grid(row=6)
entry3 = Entry(root, font=('Arial', 15, 'bold'), fg='black', justify=RIGHT, textvariable=area_variable,
state='disabled')
entry3.grid(row=8)
btn = Button(root, font=('Arial', 15, 'bold'), text='Calculate', bd=10, command=calculate)
btn.grid(row=4)
I creating a basic GUI to calculate square area and method.
I am using it in another GUI ( it's working perfectly) , I am accessing it using a button, that's why I created it a function.
It don't give any error but it don't execute result also.
I am a bigger so I am not much familiar OOPS!
It's not necessary to define two nested functions. Define one function in this way:
def calculate():
side = entry_variable.get()
area = side * side
area_variable.set(area)
perimeter = 4 * side
perimeter_variable.set(perimeter)
I'm trying to make a python(2.7) Cafe System. I created most of the functions just one function It is supposed to after I click the check button to open up the entry. Just when I click the check box button it won't open does anyone know why?
from Tkinter import *
import random
import time
import datetime
root = Tk()
root.geometry("1350x750+0+0")
root.title("Cafe Management System")
root.configure(background='black')
Tops = Frame(root, width=1350, height=100, bd=14, relief="raise")
Tops.pack(side=TOP)
f1 = Frame(root, width=900, height=650, bd=8, relief="raise")
f1.pack(side=LEFT)
f2 = Frame(root, width=440, height=650, bd=8, relief="raise")
f2.pack(side=RIGHT)
f1a = Frame(f1, width=900, height=320, bd=6, relief="raise")
f1a.pack(side=TOP)
f2a = Frame(f1, width=900, height=320, bd=6, relief = "raise")
f2a.pack(side=BOTTOM)
ft2 = Frame(f2, width= 440,height=450,bd=12,relief="raise")
ft2.pack(side=TOP)
fb2 = Frame(f2, width=440, height=250, bd=16, relief="raise")
fb2.pack(side=BOTTOM)
f1aa = Frame(f1a, width=400, height=330, bd=16, relief="raise")
f1aa.pack(side=LEFT)
f1ab = Frame(f1a, width=400, height=330, bd=16, relief="raise")
f1ab.pack(side=RIGHT)
f2aa = Frame(f2a, width=450, height=330, bd=14, relief="raise")
f2aa.pack(side=LEFT)
f2ab = Frame(f2a, width=450, height=330, bd=14, relief="raise")
f2ab.pack(side=RIGHT)
Tops.configure(background='black')
f1.configure(background='black')
f2.configure(background='black')
lblInfo = Label(Tops, font=('arial', 70, 'bold'), text="Cafe Management")
lblInfo.grid(row=0, column=0)
#===============================Functions============================
def qExit():
root.destroy()
def Reset():
PaidTax.set("")
SubTotal.set("")
TotalCost.set("")
CostofDrinks.set("")
CostofCakes.set("")
ServiceCharge.set("")
txtReciept.delete("1.0",END)
E_Latta.set("0")
E_Coffee_Cake.set("0")
#===============================Variables============================
var1=IntVar()
DateofOrder = StringVar()
Reciept_Ref = StringVar()
PaidTax = StringVar()
SubTotal = StringVar()
TotalCost = StringVar()
CostofCakes=StringVar()
CostofDrinks=StringVar()
ServiceCharge=StringVar()
E_Latta = StringVar()
E_Coffee_Cake=StringVar()
E_Coffee_Cake.set("0")
DateofOrder.set(time.strftime("%H:%M:%S"))
#=========================DRINKS======================
Latta = Checkbutton(f1ab, text="Latte \t", variable = var1, onvalue = 1, offvalue = 0,
font=('arial',18,'bold')).grid(row=0, sticky=W)
#=======================Enter Widget For Cakes=================
txtLatta = Entry(f1aa, font=('arial', 16, 'bold'), bd=8, width=6, justify='left', textvariable=E_Coffee_Cake, state=DISABLED)
txtLatta.grid(row=0, column=1)
#===========================================================Check b
def chkbutton_value():
if (var1.get() == 1):
txtLatta.configure(state=NORMAL)
elif var1.get()==0:
txtLatta.configure(state=DISABLED)
E_Latta.set("0")
#===========================================================Check btns
var1.set(0)
txtLatta.configure(state=DISABLED)
#=======================================Infomation====
lblReciept = Label(ft2, font=('arial', 12, 'bold'), text="Reciept", bd=2).grid(row=0,column=0,sticky=W,)
txtReciept = Text(fb2,font=('arial',11,'bold'), bd=8, width=59)
txtReciept.grid(row=1, column=0)
#========================================Items
lblCostofDrinks=Label(f2aa,font=('arial', 16, 'bold'), text="Cost of Drinks", bd=8)
lblCostofDrinks.grid(row=0, column=0, sticky=W)
txtCostofDrinks=Entry(f2aa, font=('arial', 16, 'bold'), bd=8,
insertwidth=2,justify='left', textvariable=CostofDrinks)
txtCostofDrinks.grid(row=0, column=1, sticky=W)
lblCostofCakes=Label(f2aa,font=('arial', 16, 'bold'), text="Cost of Cakes", bd=8)
lblCostofCakes.grid(row=1, column=0, sticky=W)
txtCostofCakes=Entry(f2aa, font=('arial', 16, 'bold'), bd=8,
insertwidth=2,justify='left',textvariable=CostofCakes)
txtCostofCakes.grid(row=1, column=1, sticky=W)
lblServiceCharge=Label(f2aa,font=('arial', 16, 'bold'), text="Service Charge", bd=8)
lblServiceCharge.grid(row=2, column=0, sticky=W)
txtServiceCharge=Entry(f2aa, font=('arial', 16, 'bold'), bd=8,
insertwidth=2, justify='left')
txtServiceCharge.grid(row=2, column=1, sticky=W)
#========================================Payment Info===================================
lblPaidTax=Label(f2ab,font=('arial', 16, 'bold'), text="Tax", bd=8)
lblPaidTax.grid(row=0, column=0, sticky=W)
txtPaidTax=Entry(f2ab, font=('arial', 16, 'bold'), bd=8,
insertwidth=2, justify='left', textvariable=PaidTax)
txtPaidTax.grid(row=0, column=1, sticky=W)
lblSubTotal=Label(f2ab,font=('arial', 16, 'bold'), text="Sub Total", bd=8)
lblSubTotal.grid(row=1, column=0, sticky=W)
txtSubTotal=Entry(f2ab, font=('arial', 16, 'bold'), bd=8,
insertwidth=2, justify='left', textvariable=SubTotal)
txtSubTotal.grid(row=1, column=1, sticky=W)
lblTotalCost=Label(f2ab,font=('arial', 16, 'bold'), text="Total", bd=8)
lblTotalCost.grid(row=2, column=0, sticky=W)
txtTotalCost=Entry(f2ab, font=('arial', 16, 'bold'), bd=8,
insertwidth=2, justify='left', textvariable=TotalCost)
txtTotalCost.grid(row=2, column=1, sticky=W)
CostofDrinks.set("")
CostofCakes.set("")
#========================================Buttons=======================
btnTotal = Button(fb2,padx=16,pady=1,bd=4,fg="black",font=('arial', 16,'bold'), width=5,
text="Total ").grid(row=3, column=1)
btnReciept = Button(fb2,padx=16,pady=1,bd=4,fg="black",font=('arial', 16,'bold'), width=5,
text="Reciept ").grid(row=3, column=2)
btnReset = Button(fb2,padx=16,pady=1,bd=4,fg="black",font=('arial', 16,'bold'), width=5,
text="Reset ", command=Reset).grid(row=3, column=3)
btnExit = Button(fb2,padx=16,pady=1,bd=4,fg="black",font=('arial', 16,'bold'), width=5,
text="Exit ",command=qExit).grid(row=3, column=4)
root.mainloop()
After taking some time on this one I noticed several formatting problems. However I am just going to answer the question about the checkbox issue.
You need to change your creation of each checkbox to include command = chkbutton_value.
Take a look at how I would create your Latta check button.
Latta = Checkbutton(f1ab, text="Latte \t", onvalue = 1, offvalue = 0,
font=('arial',18,'bold'), variable = var1, command = chkbutton_value)
NOTE: you need to make sure the function chkbutton_value(): is before the creation of your check buttons because you will get a error otherwise. NameError: name 'chkbutton_value' is not defined