所以基本上,我正在创建具有不同窗口/框架的程序。在每个这些框架上,我都希望有一个不同的小型程序,例如,一个窗口允许登录页面,然后另一个窗口允许注册。目前,我可以使用按钮在每个框架之间切换,并在每个框架上都有标签。我有一个单独的程序,它可以注册一个帐户和有关他们的信息,然后还有另一个单独的程序,它可以登录一个帐户,以检查所创建的数据库中该信息是否正确。
我现在的主要问题是,基本上将其与不同的框架合并在一起,从而在我的整个程序中实现不同的功能。我目前的主要问题是,每当我在输入框中添加程序时,程序就会继续为我不了解的 init 错误提示。(很抱歉,我的编程知识不是很高级为此,这就是为什么我要寻求帮助)
[
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
import sqlite3
class App(Tk):
def __init__(self, *args, **kwargs):
Tk.__init__(self, *args, **kwargs)
Tk.iconbitmap(self, default="fishicon3.ico")
Tk.wm_title(self, "Crumlin Fishing Club")
#Setup Menu
MainMenu(self)
#Setup Frame
container = 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, PageOne, PageTwo):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self, context):
frame = self.frames[context]
frame.tkraise()
class StartPage(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
label = Label(self, text="Start Page")
label.place(x=30,y=5)
start_page = ttk.Button(self, text="Start Page", command=lambda:controller.show_frame(StartPage))
start_page.place(x=25,y=25)
page_one = ttk.Button(self, text="Page One", command=lambda:controller.show_frame(PageOne))
page_one.place(x=25,y=50)
page_two = ttk.Button(self, text="Page Two", command=lambda:controller.show_frame(PageTwo))
page_two.place(x=25,y=75)
lblWelcome = Label(self, text="WELCOME! Welcome to the website of the Crumlin and District Angling Association owners of the fishing rights to the Crumlin River, Co. Antrim.",width=115,font=("bold", 10))
lblWelcome.place(x=500,y=50)
class PageOne(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
label = Label(self, text="Page One")
label.place(x=30,y=5)
firstNameLabel = Label(self, text="First Name",width=20,font=("bold", 10))
firstNameLabel.place(x=350,y=100)
secondNameLabel = Label(self, text="Second Name",width=20,font=("bold", 10))
secondNameLabel.place(x=350,y=125)
usernameLabel = Label(self, text="Username",width=20,font=("bold", 10))
usernameLabel.place(x=350,y=150)
passwordLabel = Label(self, text="Password",width=20,font=("bold", 10))
passwordLabel.place(x=350,y=175)
genderLabel = Label(self, text="Gender",width=20,font=("bold", 10))
genderLabel.place(x=350,y=200)
countryLabel = Label(self, text="Country",width=20,font=("bold", 10))
countryLabel.place(x=350,y=225)
start_page = ttk.Button(self, text="Start Page", command=lambda:controller.show_frame(StartPage))
start_page.place(x=25,y=25)
page_one = ttk.Button(self, text="Page One", command=lambda:controller.show_frame(PageOne))
page_one.place(x=25,y=50)
page_two = ttk.Button(self, text="Page Two", command=lambda:controller.show_frame(PageTwo))
page_two.place(x=25,y=75)
def database():
Username = username.get()
Password = password.get()
Gender = gender.get()
Country = country.get()
Animal = animal.get()
FirstName = firstName.get()
SecondName = secondName.get()
conn = sqlite3.connect('Database1.db')
with conn:
cursor=conn.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS Student (FirstName TEXT,SecondName TEXT,Gender TEXT,Country TEXT,Animal TEXT,username TEXT,password TEXT)')
cursor.execute('INSERT INTO Student (FirstName,SecondName,Gender,Country,Animal,Username,Password) VALUES(?,?,?,?,?,?,?)',(FirstName,SecondName,Gender,Country,Animal,Username,Password))
conn.commit()
class PageTwo(Frame):
def __init__(self, parent, controller):
Frame.__init__(self, parent)
label = Label(self, text="Page Two")
label.place(x=30,y=5)
start_page = ttk.Button(self, text="Start Page", command=lambda:controller.show_frame(StartPage))
start_page.place(x=25,y=25)
page_one = ttk.Button(self, text="Page One", command=lambda:controller.show_frame(PageOne))
page_one.place(x=25,y=50)
page_two = ttk.Button(self, text="Page Two", command=lambda:controller.show_frame(PageTwo))
page_two.place(x=25,y=75)
class MainMenu:
def __init__(self, master):
menubar = Menu(master)
filemenu = Menu(menubar, tearoff=0)
filemenu.add_command(label="Exit", command=master.quit)
menubar.add_cascade(label="File", menu=filemenu)
master.config(menu=menubar)
app=App()
app.geometry("1900x1000+0+0")
app.mainloop()
所以基本上这就是我的主程序的窗口,然后我试图在帐户的“第一页”注册中实现,然后在另一页上实现登录功能,但是现在我只显示注册程序,因为我不这样做在第一页上知道如何实现。
from tkinter import *
import sqlite3
root = Tk()
root.geometry('800x400')
root.title("Membership Application")
username=StringVar()
password=StringVar()
gender=StringVar()
country=StringVar()
animal=StringVar()
firstName=StringVar()
secondName=StringVar()
def database():
Username=username.get()
Password=password.get()
Gender=gender.get()
Country=country.get()
Animal=animal.get()
FirstName=firstName.get()
SecondName=secondName.get()
conn = sqlite3.connect('Database1.db')
with conn:
cursor=conn.cursor()
cursor.execute('CREATE TABLE IF NOT EXISTS Student (FirstName TEXT,SecondName TEXT,Gender TEXT,Country TEXT,Animal TEXT,username TEXT,password TEXT)')
cursor.execute('INSERT INTO Student (FirstName,SecondName,Gender,Country,Animal,Username,Password) VALUES(?,?,?,?,?,?,?)',(FirstName,SecondName,Gender,Country,Animal,Username,Password))
conn.commit()
title = Label(root, text="Registration form",width=20,font=("bold", 20))
title.place(x=90,y=53)
firstNameLabel = Label(root, text="First Name",width=20,font=("bold", 10))
firstNameLabel.place(x=50,y=100)
firstNameEntry = Entry(root,textvar=firstName)
firstNameEntry.place(x=200,y=100)
secondNameLabel = Label(root, text="Second Name",width=20,font=("bold", 10))
secondNameLabel.place(x=50,y=125)
secondNameEntry = Entry(root,textvar=secondName)
secondNameEntry.place(x=200,y=125)
usernameLabel = Label(root, text="Username",width=20,font=("bold", 10))
usernameLabel.place(x=350,y=100)
usernameEntry = Entry(root,textvar=username)
usernameEntry.place(x=500,y=100)
passwordLabel = Label(root, text="Password",width=20,font=("bold", 10))
passwordLabel.place(x=350,y=125)
passwordEntry = Entry(root,textvar=password, show ="*")
passwordEntry.place(x=500,y=125)
genderLabel = Label(root, text="Gender",width=20,font=("bold", 10))
genderLabel.place(x=70,y=230)
Radiobutton(root, text="Male",padx = 5, variable=gender, value="Male").place(x=235,y=230)
Radiobutton(root, text="Female",padx = 20, variable=gender, value="Female").place(x=290,y=230)
countryLabel = Label(root, text="Country",width=20,font=("bold", 10))
countryLabel.place(x=70,y=280)
countryList = ['Canada','India','UK','Nepal','Iceland','South Africa'];
droplist=OptionMenu(root,country, *countryList)
droplist.config(width=15)
country.set('Select your country')
droplist.place(x=240,y=280)
label_4 = Label(root, text="Animals",width=20,font=("bold", 10))
label_4.place(x=85,y=330)
animal2= IntVar()
Checkbutton(root, text="Dog", variable=animal).place(x=235,y=330)
Checkbutton(root, text="Cat", variable=animal2).place(x=290,y=330)
Button(root, text='Submit',width=20,bg='brown',fg='white',command=database).place(x=500,y=280)
root.mainloop()
最后一点不会变成代码,但这仍然是注册程序的一部分。 因此,基本上,我如何实现此目标,我尝试了多种方法来尝试访问输入框并使数据库也正常工作,但这只是没有合并在一起,我无处可寻,无法解释如何完成此特定任务每帧都有不同的功能。