1

I have created this code using tktinter in python, i am trying to get the username and password entered in by the user and display it on a different page but it just comes up blank, please help, i am quite new to tktinter and oop (so using classes and self) so i'm still very confused, if you could explain what your solutions i would be absolutely grateful. Here's my code.

from tkinter import *
import time
import tkinter as tk
LARGE_FONT= ("Verdana", 12)

class SeaofBTCapp(tk.Tk):

    def __init__(self, *args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        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 (StartPage, LoginPage):

            frame = F(container, self)

            self.frames[F] = frame

            frame.grid(row=0, column = 0, sticky="nsew")

        self.show_frame(StartPage)

    def show_frame(self, cont):
        #for frame in self.frames.values():
            #frame.grid_remove()

        frame = self.frames[cont]
        frame.tkraise()
        frame.winfo_toplevel().geometry("1024x720")

class StartPage(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text=" Page 2", font=LARGE_FONT)
        label.pack(pady=10, padx=10)
        global username
        global password

        username = StringVar()
        password = StringVar()
        name = StringVar()
        email = StringVar()
        Label(self, text="Please enter details below").pack()
        Label(self, text="").pack()
        Label(self, text="username").pack()
        usernameentry = Entry(self, textvariable=username)
        usernameentry.pack()
        Label(self, text="").pack()
        Label(self, text="password").pack()
        password = Entry(self, textvariable=password)
        password.pack()
        Button(self, text="Register", command=lambda: controller.show_frame(LoginPage)).pack()

        # usernameentry.delete(0, END)
        # passwordnameentry.delete(0, END)

class LoginPage(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        label = tk.Label(self, text=" Page 1", font=LARGE_FONT)
        label.pack(pady=10, padx=10)
        userr = username.get()
        passrr = password.get()

        Label(self, text=(
                "These are you're details \nUsername: " + userr + "\nPassword: " + passrr)).pack()
        Button(self, text="Confirm Registration").pack()
        Button(self, text="Edit Registration").pack()

        button1 = tk.Button(self, text="Home", command=lambda: controller.show_frame(StartPage))
        button1.pack()

app = SeaofBTCapp()
app.mainloop()

also i am confused what this line of code does

def __init__(self, parent, controller):

can i call this 'def__hello__'?, or does the 'def__init__' actually mean something in python? and what does it do thanks in advance for your help.

Samuel Okasia
  • 95
  • 1
  • 6
  • Is this your own code? – 10 Rep Apr 29 '20 at 17:31
  • yes i watched a tutroial on how to make multiple pages in python tktinter i used my own knowledge to manipulate the code to achieve my code, but i must say its been hard ive watched many videos, but my understanding is not at 100% – Samuel Okasia Apr 29 '20 at 17:45

0 Answers0