Reputation: 112
I'm really new to python just managing to get my head round it, here is what I have so far.
Basically I'm struggling to switch between I think (mind my coding terminology I'm new to this) i've created a parent window "root=Tk()" and I'm trying to switch to a new area of the program (open up a new window "Class window2")
So I hope you can understand my crap. If you choose to help thanks (Y)
#!/usr/bin/env python
import sqlite3
import Tkinter as tk
from Tkinter import *
conn = sqlite3.connect('Logindetails.db')
c = conn.cursor()
column_name = "Username"
attempts = 3
class welcomewindow():
def __init__(self,master):
self.master = master
self.frame = tk.Frame(master)
self.lbl = Label(master, text="Please Login")
self.lbl.pack()
self.lbl1 = Label(master, text="Username")
self.lbl1.pack()
userName=StringVar(None)
self.userBox = Entry(master, textvariable=userName)
self.userBox.pack()
self.lbl2 = Label(master, text="Password")
self.lbl2.pack()
passWord=StringVar(None)
self.passBox = Entry(master, show="*", textvariable=passWord)
self.passBox.pack()
self.logoutbut = Button(master, text="Login", width=20, command=self.Loginprocess)
self.logoutbut.pack(side='bottom', padx=15, pady=15)
self.exitbut = Button(master, text="Exit", width=20, command=self.exitProgram)
self.exitbut.pack(side='bottom', padx=15, pady=15)
def exitProgram(self):
self.master.destroy()
def Loginprocess(self):
global attempts
while attempts < 4 and attempts >= 0:
print "attempts left = " + str(attempts)
self.name = self.userBox.get()
self.password = self.passBox.get()
if self.password == "" or self.name == "":
attempts -= 1
else:
self.Checkrecord()
def Checkrecord(self):
global attempts
conn = sqlite3.connect('Logindetails.db')
cursor = conn.cursor()
query = "SELECT * FROM Logindetails WHERE Username=? ORDER BY {0}".format(column_name)
cursor.execute(query, (self.name,))
for row in cursor:
if self.name in row and self.password in row:
self.app = Window2(root)
welcomewindow.destroy()
else:
attempts -= 1
return
class Window2():
def __init__(self, master):
self.master = master
self.frame = tk.Frame(master)
# self.title("Cinema Booking System")
# self.geometry("250x250")
root = Tk()
root.title("Cinema Booking System")
root.geometry("250x250")
cls = welcomewindow(root)
root.mainloop()
Upvotes: 0
Views: 103
Reputation:
Frames have a zero width by default because there is no reason to show an empty container, so put something in them. Also you import Tkinter twice. Choose one or the other.
import Tkinter as tk
class WelcomeWindow():
def __init__(self,master):
self.master = master
##self.frame = tk.Frame(master) not used
self.lbl = tk.Label(master, text="Please Login")
self.lbl.pack()
self.lbl1 = tk.Label(master, text="Username")
self.lbl1.pack()
userName=tk.StringVar(None)
self.userBox = tk.Entry(master, textvariable=userName)
self.userBox.pack()
self.lbl2 = tk.Label(master, text="Password")
self.lbl2.pack()
passWord=tk.StringVar(None)
self.passBox = tk.Entry(master, show="*", textvariable=passWord)
self.passBox.pack()
self.logoutbut = tk.Button(master, text="New Window", width=20,
command=self.Checkrecord)
self.logoutbut.pack(padx=15, pady=15)
self.exitbut = tk.Button(master, text="Exit", width=20, command=self.exitProgram)
self.exitbut.pack(padx=15, pady=15)
def Checkrecord(self):
self.app = Window2(self.master)
def exitProgram(self):
self.master.quit()
class Window2():
def __init__(self, master):
self.master = master
self.frame = tk.Frame(self.master)
self.frame.title="Cinema Booking System"
self.frame.pack(side="bottom")
tk.Label(self.frame, text="Inside the new frame", bg="orange").pack()
root = tk.Tk()
root.title("Cinema Booking System")
root.geometry("250x250")
cls = WelcomeWindow(root)
root.mainloop()
Upvotes: 1