this might be a bit silly but I have been working on this part for like 16 hours. I am new in programming python and using class and objects. Can anyone help me out with this block of code? I am trying to call login_window to re-appear in the main frame after calling it from a top-level window. the login_window is a separate class and has been called in show_frame function defined in the Window class. I am trying to call the show_frame function in the submit function defined in signup_window. I am missing something and I can not figure out what?
import tkinter as tk
from tkinter import ttk import sqlite3 from tkinter import messagebox
LARGE_FONT = ('Verdana', 24)
class Window(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
tk.Tk.iconbitmap(self, default='logo.ico')
tk.Tk.wm_title(self, "Platforuma - IoT")
container = tk.Frame(self)
container.pack(side='top', fill='both', expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight =1)
self.frames={}
for F in (login_window, signup_window, application_window):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0,column=0, sticky='nsew')
self.show_frame(login_window)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class login_window(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
userName_label = ttk.Label(self, text='User Name')
userName_label.pack(pady=10)
userName_entry = ttk.Entry(self)
userName_entry.pack()
password_label = ttk.Label(self, text='Password')
password_label.pack(pady=10)
password_entry = ttk.Entry(self, text='Password', show='*')
password_entry.pack()
login_button = ttk.Button(self, text='Log-In', width=10, command=lambda: controller.show_frame(application_window))
login_button.pack()
signup_button = ttk.Button(self, text='Sign Up', width=10, command=lambda: controller.show_frame(signup_window))
signup_button.pack()
class signup_window(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.e1_var = tk.StringVar()
self.e2_var = tk.StringVar()
self.e3_var = tk.StringVar()
userName_label = ttk.Label(self, text='User Name')
userName_label.pack(pady=10)
userName_entry = ttk.Entry(self, textvariable=self.e1_var)
userName_entry.pack()
password_label = ttk.Label(self, text='Password')
password_label.pack(pady=10)
password_entry = ttk.Entry(self, text='Password', show='*', textvariable=self.e2_var)
password_entry.pack()
confirm_password_label = ttk.Label(self, text='Confirm Password')
confirm_password_label.pack(pady=10)
confirm_password_entry = ttk.Entry(self, text='Confirm Password', show='*', textvariable=self.e3_var)
confirm_password_entry.pack()
submit_button = ttk.Button(self, text='Submit', width=10, command= self.submit)
submit_button.place(x=70, y=180)
login_button = ttk.Button(self, text='Log-In', width=10, command=lambda: controller.show_frame(login_window))
login_button.place(x=180, y=200)
def submit(self):
conn = sqlite3.connect('dataentry.db')
c = conn.cursor()
c.execute('CREATE TABLE IF NOT EXISTS dataentry(username TEXT, password TEXT, confirmpassword TEXT)')
e1_val = self.e1_var.get()
e2_val = self.e2_var.get()
e3_val = self.e3_var.get()
c.execute("INSERT INTO dataentry (username, password, confirmpassword) VALUES (?, ?, ?)",
(e1_val, e2_val, e3_val))
conn.commit()
c.close()
conn.close()
#messagebox.showinfo("Successfull","Your information is registered. Kindly procede to Login")
win = tk.Toplevel()
win.title('Registered')
message = "Your information is registered. Kindly procede to Login"
tk.Label(win, text=message).pack()
tk.Button(win, text='Login', command=lambda: Window.show_frame(Window, login_window)).pack()
#getting error in the calling the command fuction. Everything else works fine
class application_window(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
window_label = ttk.Label(self, text='Application Window', font= LARGE_FONT)
window_label.pack(pady=10)
app = Window() app.mainloop()
Comments
Post a Comment