Related
I am trying to create an employee web app. I have created the home page, login page and application page. The application page gets the details of the candidates who want to apply for a job.
I have used tkcalendar module for selecting 'expected start date'. The GUI works fine but I am not able to get the value of the date selected.
I tried to use get_date() but it shows the following error:
self.date = self.choose_date.get_date()
AttributeError: 'Button' object has no attribute 'get_date'
This is the code I executed.
import tkinter as tk
from tkinter import ttk
import mysql.connector
from tkcalendar import *
class ABCApp(tk.Tk):
BKGR_IMAGE_PATH = 'images\\bg5.png'
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.geometry("1500x750")
main_frame = tk.Frame(self,width=200,height=50,highlightbackground="black",highlightthickness=1,background = "#e6ffe6")
main_frame.pack(side='top', fill='both', expand='True')
main_frame.grid_rowconfigure(0, weight=1)
main_frame.grid_columnconfigure(0, weight=1)
self.bkgr_image = tk.PhotoImage(file=self.BKGR_IMAGE_PATH)
self.frames = {}
for F in (HomePage,LogIn,PersonalPage,ApplicationPage):
frame = F(main_frame, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky='nsew')
self.show_frame(HomePage)
def show_frame(self,container):
frame = self.frames[container]
frame.tkraise()
class BasePage(tk.Frame):
def __init__(self, parent, controller):
super().__init__(parent)
label_bkgr = tk.Label(self, image=controller.bkgr_image)
label_bkgr.place(x=0,y=0) # Center label w/image.
class HomePage(BasePage):
def __init__(self, parent, controller):
super().__init__(parent, controller)
label = ttk.Label(self, text='Home Page', font =("Helvetica",20))
label.pack(padx=10, pady=10)
button1 = ttk.Button(self, text="Log In",
command=lambda: controller.show_frame(LogIn))
button1.pack()
class LogIn(BasePage):
def __init__(self,parent,controller):
super().__init__(parent, controller)
login_frame = tk.Frame(self, width=200, height=50, background="white")
login_frame.grid(row=400, column=20, padx=500, pady=250)
self.label_title = tk.Label(login_frame, text="Log In", font=("Helvetica", 40), bg="white")
self.label_title.grid(row=0, column=20, padx=10, pady=10)
self.label_username = tk.Label(login_frame, text="Username", font=("Helvetica", 20), bg="white")
self.label_username.grid(row=50, column=20, padx=10, pady=10)
self.entry_username = tk.Entry(login_frame, width=15, font=("Helvetica", 20), bd=3)
self.entry_username.grid(row=50, column=30, padx=10, pady=10)
self.label_password = tk.Label(login_frame, text="Password", font=("Helvetica", 20), bg="white")
self.label_password.grid(row=60, column=20, padx=10, pady=10)
self.entry_password = tk.Entry(login_frame, width=15, font=("Helvetica", 20), bd=3)
self.entry_password.grid(row=60, column=30, padx=10, pady=10)
self.login_button = tk.Button(login_frame, text="Log In",command=lambda: [self.submit(),controller.show_frame(PersonalPage)],font=("Helvetica", 20),bg="white")
self.login_button.grid(row=70, column=25, padx=10, pady=10)
def submit(self):
self.u_name = self.entry_username.get()
self.p_word = self.entry_password.get()
employee = mysql.connector.connect(host="localhost", user="root", password="", database="edatabase")
cursor_variable = employee.cursor()
cursor_variable.execute("INSERT INTO login VALUES ('" + self.u_name + "','" + self.p_word + "')")
employee.commit()
employee.close()
class PersonalPage(BasePage):
def __init__(self, parent, controller):
super().__init__(parent, controller)
personal_frame = tk.Frame(self, width=200, height=100, background="white")
personal_frame.grid(row=50, column=150, padx=300, pady=100)
personal_details_frame = tk.Frame(personal_frame,width =150,height =50,background="#e6ffe6")
personal_details_frame.grid(row =55,column =0,padx = 50,pady = 50)
self.label_title = tk.Label(personal_details_frame, text="Personal Details",font=("Helvetica", 20),bg ="#e6ffe6")
self.label_title.grid(row=10, column=0, sticky='W')
self.label_name = tk.Label(personal_details_frame, text="Name",font=("Helvetica", 12),bg ="#e6ffe6")
self.label_name.grid(row=15, column=0, padx=10, pady=10, sticky='W')
self.entry_name = tk.Entry(personal_details_frame,bd=3, font=("Helvetica", 12), width=50)
self.entry_name.grid(row=15, column=10, padx=10, pady=10, sticky='W')
self.label_email = tk.Label(personal_details_frame, text="Email id", font=("Helvetica", 12),bg ="#e6ffe6")
self.label_email.grid(row=30, column=0, padx=10, pady=10, sticky='W')
self.entry_email = tk.Entry(personal_details_frame, bd=3, font=("Helvetica", 12), width=50)
self.entry_email.grid(row=30, column=10, padx=10, pady=10, sticky='W')
self.label_mobilenumber = tk.Label(personal_details_frame, text="Mobile Number",font=("Helvetica", 12),bg ="#e6ffe6")
self.label_mobilenumber.grid(row=45, column=0, padx=10, pady=10, sticky='W')
self.entry_mobile = tk.Entry(personal_details_frame,bd=3, font=("Helvetica", 12), width=50)
self.entry_mobile.grid(row=45, column=10, padx=10, pady=10, sticky='W')
self.label_address = tk.Label(personal_details_frame, text="Address",font=("Helvetica", 12),bg ="#e6ffe6")
self.label_address.grid(row=60, column=0, padx=10, pady=10, sticky='W')
self.text_address = tk.Text(personal_details_frame,bd=3, font=("Helvetica", 12), width=50, height=5)
self.text_address.grid(row=60, column=10, padx=10, pady=10, sticky='W')
self.button_next = tk.Button(personal_details_frame,text = "Next",font = ("Helvetica",12),bg ="#b3ccff",command=lambda: [self.personal_next(),controller.show_frame(ApplicationPage)])
self.button_next.grid(row = 70,column =20,padx=10,pady=10,sticky='W')
def personal_next(self):
self.name = self.entry_name.get()
self.email = self.entry_email.get()
self.mobile = self.entry_mobile.get()
self.address = self.text_address.get("1.0","end-1c")
employee = mysql.connector.connect(host="localhost", user="root", password="", database="edatabase")
cursor_variable = employee.cursor()
cursor_variable.execute("INSERT INTO personal VALUES ('" + self.name + "','" + self.email + "','" + self.mobile + "','" + self.address + "')")
employee.commit()
employee.close()
class ApplicationPage(BasePage):
def __init__(self, parent, controller):
super().__init__(parent, controller)
application_frame = tk.Frame(self, width=200, height=100, background="white")
application_frame.grid(row=50, column=150, padx=300, pady=100)
application_details_frame = tk.Frame(application_frame, width=150, height=50, background="#e6ffe6")
application_details_frame.grid(row=55, column=0, padx=50, pady=50)
self.label_title = tk.Label(application_details_frame, text="Application Details", font=("Helvetica", 20),bg="#e6ffe6")
self.label_title.grid(row=10, column=0, sticky='W')
self.label_position = tk.Label(application_details_frame, text="Applied for Position", font=("Helvetica", 12),bg ="#e6ffe6")
self.label_position.grid(row=75, column=0, padx=10, pady=10, sticky='W')
self.list_box1 = tk.Listbox(application_details_frame, width=50, height=3, font=("Helvetica", 12))
self.list_box1.insert(1, "Database Admin")
self.list_box1.insert(2, "Network Admin")
self.list_box1.insert(3, "Deployment Admin")
self.list_box1.grid(row=75, column=10, padx=10, pady=10, sticky='w')
self.label_date = tk.Label(application_details_frame, text="Expected Start Date", font=("Helvetica", 12),bg ="#e6ffe6")
self.label_date.grid(row=90, column=0, padx=10, pady=10, sticky='W')
self.choose_date = tk.Button(application_details_frame, text="Choose Available Date", command=lambda: self.open_calendar(), width=49, bg="white",font=("Helvetica", 12), anchor='w')
self.choose_date.grid(row=90, column=10, padx=10, pady=10, sticky='w')
self.label_proficiency = tk.Label(application_details_frame, text="Proficient Language", font=("Helvetica", 12),bg ="#e6ffe6")
self.label_proficiency.grid(row=120, column=0, padx=10, pady=10, sticky='W')
self.radio = tk.IntVar()
self.radio_button1 = tk.Radiobutton(application_details_frame, text="Java", variable=self.radio, value=1, font=("Helvetica", 12),bg ="#e6ffe6")
self.radio_button1.grid(row=120, column=10, padx=10, pady=10, sticky='w')
self.radio_button2 = tk.Radiobutton(application_details_frame, text="SQL", variable=self.radio, value=2, font=("Helvetica", 12),bg ="#e6ffe6")
self.radio_button2.grid(row=135, column=10, padx=10, pady=10, sticky='w')
self.radio_button3 = tk.Radiobutton(application_details_frame, text="C", variable=self.radio, value=3, font=("Helvetica", 12),bg ="#e6ffe6")
self.radio_button3.grid(row=150, column=10, padx=10, pady=10, sticky='w')
self.submit_button = tk.Button(application_details_frame,text = "Submit",command = self.submit(),font = ("Helvetica",12),bg ="#b3ccff")
self.submit_button.grid(row = 220,column =10,padx=10,pady=10,sticky='W')
def submit(self):
self.position = self.list_box1.get(tk.ANCHOR)
self.date = self.choose_date.get_date()
employee = mysql.connector.connect(host="localhost", user="root", password="", database="edatabase")
cursor_variable = employee.cursor()
cursor_variable.execute("INSERT INTO application VALUES ('" + self.position + "','"+self.date+"')")
employee.commit()
employee.close()
def open_calendar(self):
self.toplevel1 = tk.Toplevel(self)
self.calendar_variable = Calendar(self.toplevel1, selectmode="day", year=2021, month=4, day=10)
self.calendar_variable.pack()
self.toplevel1.mainloop()
app = ABCApp()
app.mainloop()
Any help is appreciated.
First the following line:
self.submit_button = tk.Button(application_details_frame,text = "Submit",command = self.submit(),font = ("Helvetica",12),bg ="#b3ccff")
will execute self.submit() immediately. It should be:
self.submit_button = tk.Button(application_details_frame, text="Submit", command=self.submit, font=("Helvetica",12), bg="#b3ccff")
Second as the error said, self.choose_date is a tk.Button not tkcalendar.Calendar. Better create an instance variable of tk.StringVar and associate it to the tkcalendar.Calendar widget. Then you can use this instance variable to get the selected date:
class ApplicationPage(BasePage):
def __init__(self, parent, controller):
...
self.selected_date = tk.StringVar()
def submit(self):
self.position = self.list_box1.get(tk.ANCHOR)
self.date = self.selected_date.get() # get the selected date
...
def open_calendar(self):
...
self.calendar_variable = Calendar(self.toplevel1, selectmode="day", year=2021, month=4, day=10,
textvariable=self.selected_date)
...
Good day.
I am attempting to create an options selection menu for a school assignment.
I am using the Python 3.7.2 Themed Tkinter library in order to display this program properly. However, I am having some issues getting my ttk.Checkbutton() widgets to display appropriately. However, while the Checkbutton() is set to be unchecked by default, it is displaying a black square within the button. I have confirmed that this black square represents a false value, as when I click it it displays the true check. When I uncheck it, however, it becomes blank rather than returning to the black square state.
I have checked this issue with both BooleanVar() and IntVar() values, with the same issue.
Here is an excerpt from the code, which is functional:
from tkinter import *
from tkinter import ttk
root = Tk()
root.title("Order Manager")
menu__pizza_1_count = IntVar()
menu__pizza_1_count.set(0)
menu__pizza_1_cheese = BooleanVar()
menu__pizza_1_cheese.set(False)
menu__pizza_1_bacon = BooleanVar()
menu__pizza_1_bacon.set(False)
menu__pizza_1_label = ttk.Label(root, text="A Shrubbery")
menu__pizza_1_label.grid(row=0, column=0, columnspan=2, padx=5, pady=5)
menu__pizza_1_price = ttk.Label(root, text="$8.50")
menu__pizza_1_price.grid(row=1, column=0, columnspan=1, padx=5, pady=5)
menu__pizza_1_current = ttk.Label(root, textvariable=menu__pizza_1_count)
menu__pizza_1_current.grid(row=1, column=1, padx=5, pady=5)
menu__pizza_1_cheese = ttk.Checkbutton(root, text="Cheese", variable=menu__pizza_1_cheese, offvalue=False, onvalue=True)
menu__pizza_1_cheese.grid(row=2, column=0, pady=5)
menu__pizza_1_bacon = ttk.Checkbutton(root, text="Bacon", variable=menu__pizza_1_bacon, offvalue=False, onvalue=True)
menu__pizza_1_bacon.grid(row=2, column=1, pady=5)
menu__pizza_1_increase = ttk.Button(root, width=7, text="+") #add count COMMAND
menu__pizza_1_increase.grid(row=3, column=0, padx=5, pady=5)
menu__pizza_1_decrease = ttk.Button(root, width=7, text="-") #decrease count COMMAND
menu__pizza_1_decrease.grid(row=3, column=1, padx=5, pady=5)
[This is what the end result looks like on my end][1]
Does anyone have any suggestions on how to get it do display as blank by default?
Regards,
Elliott
[1]: https://i.stack.imgur.com/DfzMT.png
You checkbox name in the same as the variable name. If you use different names, the checkboxes work correctly.
from tkinter import *
from tkinter import ttk
root = Tk()
root.title("Order Manager")
vmenu__pizza_1_count = IntVar()
vmenu__pizza_1_count.set(0)
vmenu__pizza_1_cheese = BooleanVar()
vmenu__pizza_1_cheese.set(False)
vmenu__pizza_1_bacon = BooleanVar()
vmenu__pizza_1_bacon.set(False)
menu__pizza_1_label = ttk.Label(root, text="A Shrubbery")
menu__pizza_1_label.grid(row=0, column=0, columnspan=2, padx=5, pady=5)
menu__pizza_1_price = ttk.Label(root, text="$8.50")
menu__pizza_1_price.grid(row=1, column=0, columnspan=1, padx=5, pady=5)
menu__pizza_1_current = ttk.Label(root, textvariable=vmenu__pizza_1_count)
menu__pizza_1_current.grid(row=1, column=1, padx=5, pady=5)
menu__pizza_1_cheese = ttk.Checkbutton(root, text="Cheese", variable=vmenu__pizza_1_cheese, offvalue=False, onvalue=True)
menu__pizza_1_cheese.grid(row=2, column=0, pady=5)
menu__pizza_1_bacon = ttk.Checkbutton(root, text="Bacon", variable=vmenu__pizza_1_bacon, offvalue=False, onvalue=True)
menu__pizza_1_bacon.grid(row=2, column=1, pady=5)
menu__pizza_1_increase = ttk.Button(root, width=7, text="+") #add count COMMAND
menu__pizza_1_increase.grid(row=3, column=0, padx=5, pady=5)
menu__pizza_1_decrease = ttk.Button(root, width=7, text="-") #decrease count COMMAND
menu__pizza_1_decrease.grid(row=3, column=1, padx=5, pady=5)
root.mainloop()
Startup Output
im making a program that will make my mother accounting more easily.
so i still had this problem to run function that will insert data to treeview. and the button in other class.
sry im newbie here :D
i already tried make function in local class that call the class with treeview, but it still give me error init() missing 1 required positional argument: 'master'
this my class with treeview and function that will insert data into tree view :
class windowHitung():
def __init__(self, master):
self.master=master
self.data = dataHolder()
self.w1=tk.Toplevel(self.master)
self.w1.wm_title("Program Hitung Untung dari modal")
self.frameMenuHitung=Frame(self.w1, width=100, height=50)
self.frameMenuHitung.grid(row=0, column=0)
self.treeItems = ttk.Treeview(self.frameMenuHitung, columns=("nama", "jumlah", "harga"))
self.treeItems['show'] = 'headings'
self.treeItems.column('nama', anchor=N)
self.treeItems.column('jumlah', anchor=N)
self.treeItems.column('harga', anchor=N)
self.treeItems.heading('nama', text="Nama Barang")
self.treeItems.heading('jumlah', text="Jumlah")
self.treeItems.heading('harga', text="Harga")
self.treeItems.grid(row=0, column=0)
self.itemscroll = ttk.Scrollbar(self.frameMenuHitung, command=self.treeItems.yview)
self.itemscroll.grid(row=0, column=1, sticky='nsw')
self.treeItems.config(yscrollcommand=self.itemscroll.set)
self.labelModal = Label(self.frameMenuHitung, text="Modal ")
self.labelModal.grid(row=1, column=0, sticky='w', padx=5)
self.entryModal = Entry(self.frameMenuHitung)
self.entryModal.grid(row=1, column=0, sticky='n')
self.buttonTambah = ttk.Button(self.frameMenuHitung, text="Tambah", command=self.barangInputShow)
self.buttonTambah.grid(row=2, column=0, padx=5, pady=5, sticky='w')
self.buttonEdit = ttk.Button(self.frameMenuHitung, text="Edit")
self.buttonEdit.grid(row=2, column=0, padx=5, pady=5, sticky='n')
self.buttonBuang = ttk.Button(self.frameMenuHitung, text="Buang")
self.buttonBuang.grid(row=2, column=0, padx=5, pady=5, sticky='e')
def insertValue(self):
self.treeItems.insert("", END, values=(dataHolder.namaBarang,"",""))
def barangInputShow(self):
inputBarang(self.master)
and this the toplevel that will be inputdata for the treeview.
class inputBarang(windowHitung):
def __init__(self, master):
self.master = master
self.windowHitung = windowHitung()
self.inputBarang = Toplevel(self.master)
self.inputBarang.title("Input Item Properties")
self.frameInput = Frame(self.inputBarang)
self.frameInput.grid(row=0, column=0)
self.labelBarang = Label(self.frameInput, text="Nama Barang")
self.labelBarang.grid(row=0, column=0, sticky='w', padx=5, pady=6)
self.entryBarang = Entry(self.frameInput)
self.entryBarang.grid(row=0, column=1, sticky='w', padx=3, pady=6)
self.labelJumlah = Label(self.frameInput, text="Jumlah Barang")
self.labelJumlah.grid(row=1, column=0, sticky='w', padx=5, pady=6)
self.entryJumlah = Entry(self.frameInput)
self.entryJumlah.grid(row=1, column=1, sticky='w', padx=3, pady=6)
self.labelHarga = Label(self.frameInput, text="Harga")
self.labelHarga.grid(row=2, column=0, sticky='w', padx=5, pady=6)
self.entryHarga = Entry(self.frameInput)
self.entryHarga.grid(row=2, column=1, sticky='w', padx=3, pady=6)
self.buttonInsertBarang = Button(self.frameInput, text="Tambah barang", width=20, height=5, command=self.windowHitung.insertValue)
self.buttonInsertBarang.grid(row=3, columnspan=2, sticky="n")
if you need full code. :
from tkinter import *
from tkinter import ttk, messagebox
import tkinter as tk
from Hitung import *
import Hitung as cnt
class mainWindow():
def keluar():
pesanKeluar = messagebox.askyesno("Alert", "Apakah anda ingin keluar?")
if pesanKeluar == True:
root.destroy()
else:
pass
def __init__(self, master):
self.master=master
self.frameMainMenu=Frame(master, width=100, height=50)
self.frameMainMenu.pack()
self.buttonHitung=Button(self.frameMainMenu, text="Hitung", command=self.windowHitungShow)
self.buttonHitung.grid(row=0, padx=5, pady=2)
self.buttonLihatRiwayat=Button(self.frameMainMenu, text="Riwayat")
self.buttonLihatRiwayat.grid(row=1, padx=5, pady=2)
self.buttonKeluar=Button(self.frameMainMenu, text="Keluar", command=mainWindow.keluar)
self.buttonKeluar.grid(row=2, padx=5, pady=2)
def windowHitungShow(self):
windowHitung(self.master)
class dataHolder():
namaBarang="test"
jumlahBarang=0
hargaBarang=00
def __init__(self):
dataHolder.namaBarang="test"
dataHolder.jumlahBarang=0
dataHolder.hargaBarang=0
class windowHitung():
def __init__(self, master):
self.master=master
self.data = dataHolder()
self.w1=tk.Toplevel(self.master)
self.w1.wm_title("Program Hitung Untung dari modal")
self.frameMenuHitung=Frame(self.w1, width=100, height=50)
self.frameMenuHitung.grid(row=0, column=0)
self.treeItems = ttk.Treeview(self.frameMenuHitung, columns=("nama", "jumlah", "harga"))
self.treeItems['show'] = 'headings'
self.treeItems.column('nama', anchor=N)
self.treeItems.column('jumlah', anchor=N)
self.treeItems.column('harga', anchor=N)
self.treeItems.heading('nama', text="Nama Barang")
self.treeItems.heading('jumlah', text="Jumlah")
self.treeItems.heading('harga', text="Harga")
self.treeItems.grid(row=0, column=0)
self.itemscroll = ttk.Scrollbar(self.frameMenuHitung, command=self.treeItems.yview)
self.itemscroll.grid(row=0, column=1, sticky='nsw')
self.treeItems.config(yscrollcommand=self.itemscroll.set)
self.labelModal = Label(self.frameMenuHitung, text="Modal ")
self.labelModal.grid(row=1, column=0, sticky='w', padx=5)
self.entryModal = Entry(self.frameMenuHitung)
self.entryModal.grid(row=1, column=0, sticky='n')
self.buttonTambah = ttk.Button(self.frameMenuHitung, text="Tambah", command=self.barangInputShow)
self.buttonTambah.grid(row=2, column=0, padx=5, pady=5, sticky='w')
self.buttonEdit = ttk.Button(self.frameMenuHitung, text="Edit")
self.buttonEdit.grid(row=2, column=0, padx=5, pady=5, sticky='n')
self.buttonBuang = ttk.Button(self.frameMenuHitung, text="Buang")
self.buttonBuang.grid(row=2, column=0, padx=5, pady=5, sticky='e')
def insertValue(self):
self.treeItems.insert("", END, values=(dataHolder.namaBarang,"",""))
def barangInputShow(self):
inputBarang(self.master)
class inputBarang(windowHitung):
def __init__(self, master):
self.master = master
self.windowHitung = windowHitung()
self.inputBarang = Toplevel(self.master)
self.inputBarang.title("Input Item Properties")
self.frameInput = Frame(self.inputBarang)
self.frameInput.grid(row=0, column=0)
self.labelBarang = Label(self.frameInput, text="Nama Barang")
self.labelBarang.grid(row=0, column=0, sticky='w', padx=5, pady=6)
self.entryBarang = Entry(self.frameInput)
self.entryBarang.grid(row=0, column=1, sticky='w', padx=3, pady=6)
self.labelJumlah = Label(self.frameInput, text="Jumlah Barang")
self.labelJumlah.grid(row=1, column=0, sticky='w', padx=5, pady=6)
self.entryJumlah = Entry(self.frameInput)
self.entryJumlah.grid(row=1, column=1, sticky='w', padx=3, pady=6)
self.labelHarga = Label(self.frameInput, text="Harga")
self.labelHarga.grid(row=2, column=0, sticky='w', padx=5, pady=6)
self.entryHarga = Entry(self.frameInput)
self.entryHarga.grid(row=2, column=1, sticky='w', padx=3, pady=6)
self.buttonInsertBarang = Button(self.frameInput, text="Tambah barang", width=20, height=5, command=self.windowHitung.insertValue)
self.buttonInsertBarang.grid(row=3, columnspan=2, sticky="n")
if __name__=="__main__":
root=Tk()
root.wm_title("Program Hitung Untung dari modal")
#root.geometry("200x200")
main = mainWindow(root)
root.mainloop()
thanks to see my request
i expect to make the button run the funcion, but it still give me errors
from tkinter import*
def convert2c():
try:
f = float(tempIN.get())
c = (f-32)*5.0/9.0
tempOUTc.set(c)
except ValueError:
pass
def convert2f():
try:
c = float(tempIN.get())
f = c*9.0/5.0 + 32
tempOUTf.set(f)
except ValueError:
pass
root = Tk()
f = root
root.title("Temperature Converter")
root.geometry('{}x{}'.format(500,200))
topFrm = Frame(root, width=500, height=80, bg="#e01111")
midFrm = Frame(root, width=500, height=150, bg="#795fb5")
btmFrm = Frame(root, width=500, height=100)
btmL = Frame(btmFrm, width=250, height=100, bg="#4117a5")
btmR = Frame(btmFrm, width=250, height=100, bg="#3f454f")
topFrm.grid(row=0, sticky="W")
midFrm.grid(row=1)
btmFrm.grid(row=3)
btmL.grid(row=2, column=0)
btmR.grid(row=2, column=2)
tempIN = StringVar()
tempOUTc = StringVar()
tempOUTf = StringVar()
Label(f, text="Temperature Converter\n A number in temperature degree is converted into another as one of the button is clicked").grid(column=0, row=0)
Label(f, text="Enter a Temperature").grid(column=0, row=1)
Entry(f, textvariable=tempIN, width=10) .grid(column=0, rowspan=1, row=1, sticky=W)
Button(f, text=" to Celsius", command=convert2c) .grid(column=0, row=3, sticky=W)
Button(f, text=" to Fahrenheit", command=convert2f) .grid(column=1, row=3, sticky=W)
Label(f, textvariable=tempOUTc) .grid(column=2, row=1, sticky=W)
Label(f, textvariable=tempOUTf) .grid(column=2, row=2, sticky=W)
root.mainloop()
I am having quite the trouble using classes in python. The first code I used in changing and showing a new window works but too cluttered so i decided to use the class. but there might be something wrong in my code. Can you atleast see to it? Thank you. Hoping for a fast response.
import random, sys, os, rabinMiller, cryptomath
from tkinter import *
import tkinter as tk
from PIL import Image, ImageTk
from tkinter.filedialog import askopenfile
class MainFrame(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
#frame1.title("RSA Cryptosystem")
#frame1.config(bg="black")
container.columnconfigure(0, weight=1)
container.rowconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, DecryptionPage, EncryptionPage, MakeKeyPage):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky=(N, W, E, S))
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
image4 = Image.open("rsa cryptosystem logo.jpg")
photo4 = ImageTk.PhotoImage(image4)
label1 = tk.Label(self, image=photo4)
label1.grid(column=1, row=1, columnspan=3, padx=5, pady=5)
label1.image = photo4
image1 = Image.open("MAKE KEY.jpg")
photo1 = ImageTk.PhotoImage(image1)
image2 = Image.open("encryption button.jpg")
photo2 = ImageTk.PhotoImage(image2)
image3 = Image.open("decryption button.jpg")
photo3 = ImageTk.PhotoImage(image3)
button1 = tk.Button(self, compound=TOP, command=lambda: controller.show_frame(MakeKeyPage), width=338, height=338, image=photo1)
button1.grid(column=1, row=2, sticky=S, rowspan=2, padx=5, pady=5)
button1.image = photo1
button2 = tk.Button(self, compound=TOP, command=lambda: controller.show_frame(EncryptionPage), width=525, height=150, image=photo2)
button2.grid(column=2, row=2, sticky=(W, E), columnspan=2, padx=5, pady=5)
button2.image = photo2
button3 = tk.Button(self, compound=TOP, command=lambda: controller.show_frame(DecryptionPage), width=525, height=150, image=photo3)
button3.grid(column=2, row=3, sticky=(W, E), columnspan=2, padx=5, pady=5)
button3.image = photo3
class DecryptionPage(tk.Frame):
def __init__(self, parent, controller):
textframe1 = tk.Text(self, width=70, height=32).grid(column=3, row=2, rowspan=3, padx=5, pady=5, sticky=(S, E))
image5 = Image.open("INSERT PRIVATE KEY.jpg")
photo5 = ImageTk.PhotoImage(image5)
image6 = Image.open("INSERT ENCRYPTED TEXT.jpg")
photo6 = ImageTk.PhotoImage(image6)
image7 = Image.open("DECRYPT.jpg")
photo7 = ImageTk.PhotoImage(image7)
button4 = tk.Button(self, width=338, height=80, image=photo5, command=open_file)
button4.grid(column=1, row=2,columnspan=2, sticky=N)
button4.image = photo5
button5 = tk.Button(self, width=338, height=80, image=photo6, command=open_file)
button5.grid(column=1, row=3, columnspan=2, sticky=N)
button5.image = photo6
button6 = tk.Button(self, text="BACK", command=lambda: controller.show_frame(StartPage))
button6.grid(column=1, row=1, padx=5, pady=5, sticky=W)
button7 = tk.Button(self, width=338, height=338, image=photo7)
button7.grid(column=1, row=4, padx=5, pady=5, columnspan=2, sticky=S)
button7.image = photo7
class EncryptionPage(tk.Frame):
def __init__(self, parent, controller):
textframe2 = tk.Text(self, width=70, height=32).grid(column=3, row=2, columnspan=2, rowspan=3, padx=5, pady=5, sticky=(S, E))
image8 = Image.open("INSERT PUBLIC KEY.jpg")
photo8 = ImageTk.PhotoImage(image8)
image9 = Image.open("ENCRYPT.jpg")
photo9 = ImageTk.PhotoImage(image9)
button8 = tk.Button(self, width=338, height=80, image=photo8, command=open_file)
button8.grid(column=1, row=2,columnspan=2, sticky=N)
button8.image = photo8
button10 = tk.Button(self, text="BACK", command=lambda: controller.show_frame(StartPage))
button10.grid(column=1, row=1, padx=5, pady=5, sticky=W)
button9 = tk.Button(self, width=338, height=338, image=photo9)
button9.grid(column=1, row=4, padx=5, pady=5, columnspan=2, sticky=S)
button9.image = photo9
receivename = StringVar()
receivename_entry = tk.Entry(self, width=85, textvariable=receivename).grid(column=4, row=1, padx=5, pady=5, sticky=(W, E))
label4 = tk.Label(self, text="TO: ").grid(column=3, row=1, padx=5, pady=5, sticky=W)
class MakeKeyPage(tk.Frame):
def __init__(self, parent, controller):
keyname = StringVar()
phone = StringVar()
keyname_entry = tk.Entry(self, width=15, textvariable=keyname)
keyname_entry.grid(column=2, row=2, sticky=E, padx=5, pady=5)
label2 = tk.Label(self, text="Key Name: ")
label2.grid(column=1, row=2, sticky=W, padx=5, pady=5)
label3 = tk.Label(self, text="Key Type: ")
label3.grid(column=1, row=3, sticky=W, padx=5, pady=5)
button12 = tk.Button(self, text="BACK", command=lambda: controller.show_frame(StartPage)).grid(column=1, row=1, padx=5, pady=5, sticky=W)
prime = tk.Radiobutton(self, text="Prime", variable=phone, value='prime').grid(column=1, row=4, sticky=(W, E))
luckyprime = tk.Radiobutton(self, text="Lucky Prime", variable=phone, value='luckyprime').grid(column=2, row=4, sticky=(W, E))
button11 = tk.Button(self, text="Generate Keys").grid(column=1, row=5, columnspan=2, sticky=(W, E))
app = MainFrame()
app.mainloop()