我对python真的是个新手,只是设法让我的头脑清醒过来,这里是我目前所拥有的。你知道吗
基本上,我正在努力切换我认为(注意我的编码术语,我是新手)我已经创建了一个父窗口“root=Tk()”,我正在尝试切换到程序的一个新区域(打开一个新窗口“Class window2”)
所以我希望你能理解我的废话。如果你选择帮忙,谢谢
#!/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()
默认情况下,帧的宽度为零,因为没有理由显示空容器,所以在帧中放置一些内容。您还可以导入Tkinter两次。选择一个或另一个。你知道吗
相关问题 更多 >
编程相关推荐