我真的很陌生,只是设法让我的头脑,这是我到目前为止。
基本上我正在努力在我之间切换(请注意我的编码术语我不熟悉这一点)我创建了一个父窗口" root = Tk()&#34 ;我试图切换到程序的新区域(打开一个新窗口" Class window2")
所以我希望你能理解我的废话。如果你选择帮助谢谢(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()
答案 0 :(得分:1)
默认情况下,框架的宽度为零,因为没有理由显示空容器,因此请在其中放置一些内容。你也两次导入Tkinter。选择其中一个。
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()