我开始使用 Python,我对它还很陌生,所以我试图让我的主文件与其他页面一起在单独的 python 文件中运行。我不断收到同样的错误。
import tkinter as tk
from tkinter import *
from tkinter import ttk
import options as options
from StartPage import StartPage
from PageDecryption import Page2, Page2a, Page2b, Page2c
from PageEncryption import Page1, Page1a, Page1b, Page1c
LARGEFONT = ("Verdana", 35)
class tkinterApp(tk.Tk):
# __init__ function for class tkinterApp
def __init__(self, *args, **kwargs):
# __init__ function for class Tk
tk.Tk.__init__(self, *args, **kwargs)
# creating a container
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
# initializing frames to an empty array
self.frames = {}
# iterating through a tuple consisting
# of the different page layouts
for F in (StartPage, Page1, Page2, Page1a, Page1b, Page1c, Page2a, Page2b, Page2c):
frame = F(container, self)
# initializing frame of that object from
# startpage, page1, page2 respectively with
# for loop
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(StartPage)
# to display the current frame passed as
# parameter
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
# Driver Code
app = tkinterApp()
app.mainloop()
import tk as tk
from tkinter import ttk
import tkinter
import StartPage
LARGEFONT = ("Verdana", 35)
class Page2(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = ttk.Label(self, text="Decryption", font=LARGEFONT)
label.grid(row=0, column=4, padx=10, pady=10)
# button to show frame 2 with text
# layout2
#button2 = ttk.Button(self, text="Encryption",
# command=lambda: controller.show_frame(Page1))
# putting the button in its place by
# using grid
#button2.grid(row=1, column=1, padx=10, pady=10)
# button to show frame 3 with text
# layout3
button2 = ttk.Button(self, text="Startpage",
command=lambda: controller.show_frame(StartPage))
# putting the button in its place by
# using grid
button2.grid(row=2, column=1, padx=10, pady=10)
button2a = ttk.Button(self, text="Caeser",
command=lambda: controller.show_frame(Page2a))
# putting the button in its place by
# using grid
button2a.grid(row=4, column=4, padx=10, pady=10)
button2b = ttk.Button(self, text="Rail Method",
command=lambda: controller.show_frame(Page2b))
# putting the button in its place by
# using grid
button2b.grid(row=2, column=4, padx=10, pady=10)
button2c = ttk.Button(self, text="Blowfish",
command=lambda: controller.show_frame(Page2c))
# putting the button in its place by
# using grid
button2c.grid(row=2, column=5, padx=10, pady=10)
我试图将文件拆分为多个文件以便于阅读,但我一直运行到模块“tk”没有属性“Frame”错误