Tkinter Image not Displaying when rendering class objects with multiple frames - python-3.x

I've created a desktop application using Tkinter in python3. There is a main class object 'Stack' for the application and within it is a function to render multiple frames for navigation to other windows within the app on a button click event.
I'm trying to display an image on the 'HomePage' screen (and actually all pages as a heading) using PIL.ImageTk/PIL.Image. Every time I run the app from terminal (macOS), the desktop app runs but the image does not appear. What am I doing wrong? Here is my code:
import getpass
import tkinter as tk
from tkinter import ttk
from PIL import ImageTk, Image
LARGE_FONT = ('Source Code Pro', 24)
class Stack(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.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 (HomePage, NdA):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky='news')
self.show_frame(HomePage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class HomePage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
username = getpass.getuser()
logo_path = 'myfilepath'.format(username)
img = ImageTk.PhotoImage(Image.open(logo_path+'myimage.png').resize((120,120)))
l = tk.Label(self, image=img)
l.grid(column=0, row=0, ipadx=10, ipady=5, sticky='w')
ttk.Label(
self,
text='Some Text',
wraplength=450,
justify=tk.LEFT
).grid(
column=1,
row=0,
ipady=10,
padx=(0,10),
sticky='nw')
tier1 = tk.Button(self, text='Button1', state=tk.DISABLED).grid(column=0, row=3, padx=10, columnspan=2, sticky='nesw')
tier2 = tk.Button(self, text='Button2', state=tk.DISABLED).grid(column=0, row=4, padx=10, columnspan=4, sticky='nesw')
tier3 = ttk.Button(self, text='Button3', command=lambda: controller.show_frame(Tier3))
tier3.grid(column=0, row=5, padx=10, columnspan=4, sticky='nesw')
nda = ttk.Button(self, text='Button4', command=lambda: controller.show_frame(NdA))
nda.grid(column=0, row=6, padx=10, pady=(0,10), columnspan=4, sticky='nesw')
class NdA(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
def clear_form():
effective_date.delete(0, END)
client_name.delete(0, END)
address.delete(0, END)
user_initials.delete(0, END)
def submit_data():
functions.create_nda(
date=effective_date.get(),
client_name=client_name.get(),
address=address.get(),
user=user_initials.get()
)
effective_date.delete(0, tk.END)
client_name.delete(0, tk.END)
address.delete(0, tk.END)
user_initials.delete(0, tk.END)
messagebox.showinfo('Heading Text', 'Message Text')
tk.Label(
self,
text='Some Text',
wraplength=450,
justify=tk.LEFT
).grid(
column=1,
row=0,
columnspan=3,
ipady=10,
padx=(0,10),
sticky='nw')
tk.Label(self, text='Label1').grid(column=0, row=2, pady=(20,10), columnspan=4, sticky='news')
tk.Label(self, text='Data1').grid(column=0, row=3, padx=(10,0), sticky='w')
client_name = tk.Entry(self, width=30)
client_name.grid(column=1, row=3, columnspan=3, padx=(0,10), sticky='news')
tk.Label(self, text='Data2').grid(column=0, row=5, padx=(10,0), sticky='w')
address = tk.Entry(self, width=30)
address.grid(column=1, row=5, columnspan=3, padx=(0,10), sticky='news')
tk.Label(self, text='Data3').grid(column=0, row=6, padx=(10,0), sticky='w')
effective_date = tk.Entry(self, width=30)
effective_date.insert(1, ' mm/dd/yyyy')
effective_date.grid(column=1, row=6, columnspan=3, padx=(0,10), sticky='news')
tk.Label(self, text='Data4').grid(column=0, row=7, padx=(10,0), sticky='w')
user_initials = tk.Entry(self, width=30)
user_initials.grid(column=1, row=7, columnspan=3, padx=(0,10), sticky='news')
create_tier3 = tk.Button(self, text='or click me', command=submit_data).grid(column=3, row=8, pady=(30,10), padx=(0,10), sticky='news')
clear_form = tk.Button(self, text='click me', command=clear_form).grid(column=2, row=8, pady=(30,10), padx=(5,5), sticky='news')
# return_home = tk.Button(self, text='HOME').grid(column=1, row=8, pady=(30,10), sticky='news')
app = Stack()
app.mainloop()

When the __init__() function in class HomePage exits the name img is garbage collected and so the label can't remember it. You need to save a reference to the image. The usual way is to save it as an attribute to the label:
l = tk.Label(self, image=img)
l.image = img # Save reference to image

Related

Tkinter objects are not centering

I am trying to create a simple Python 3.x GUI project with tkinter, just to learn the language better (I started learning Python not long ago), of which the only thing it does is switching between different pages as a button is clicked. The problem is that the objects are not getting in the center of the screen. What's wrong in my code?
Images:
Start Page
First Page
Second Page
import tkinter as tk
LARGE_FONT = ("verdana", 10)
class Application(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
container.grid()
self.frames = {}
for F in (StartPage, PageOne, PageTwo):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="snew")
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class StartPage (tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label1 = tk.Label(self, text="Start Page", font=LARGE_FONT)
label1.grid(row=0, column=0)
button1 = tk.Button(self, text="Go to Page One",
command=lambda: controller.show_frame(PageOne))
button1.grid(row=1, column=0)
button2 = tk.Button(self, text="Go to Page Two",
command=lambda: controller.show_frame(PageTwo))
button2.grid(row=2, column=0)
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label2 = tk.Label(self, text="Page One", font=LARGE_FONT)
label2.grid(row=0, column=0, sticky="E")
button2 = tk.Button(self, text="Go to Page Two",
command=lambda: controller.show_frame(PageTwo))
button2.grid(row=1, column=0)
button3 = tk.Button(self, text="Go to Start Page",
command=lambda: controller.show_frame(StartPage))
button3.grid(row=2, column=0)
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label2 = tk.Label(self, text="Page Two", font=LARGE_FONT)
label2.grid(row=0, column=0,sticky="E")
button2 = tk.Button(self, text="Go to Page One",
command=lambda: controller.show_frame(PageOne))
button2.grid(row=1, column=0)
button3 = tk.Button(self, text="Go to Start Page",
command=lambda: controller.show_frame(StartPage))
button3.grid(row=2, column=0)
app = Application()
app.title("Application")
app.mainloop()
I put a menu on the left with tkinter. Everything to the right of the menu is aligned in the middle. How to align to the right of the menu
There is a text on the back of the textbox, but because it is center-aligned, it crosses over the text and the text does not appear.
Tkinter program
All code:
from tkinter import *
from tkinter import messagebox
import tkinter.font as font
import tkinter as tkMessageBox
from typing import Sized
from PIL import ImageTk, Image
window = Tk()
window.title("Ogretmen+")
window.geometry("900x447")
window.configure(bg="#202020")
genelgorunumbaslik = font.Font(size=20)
menuyazilar = font.Font(size=20)
guncellemebuyuk = font.Font(size=15)
def sinifYonetimi():
sinifyonetimiaciklama.config(text="Sınıf yönetimi kısmına hoş geldiniz. Bu bölümden sınıf ekleyebilir ve silebilirsiniz. Örnek sınıf adı: 10 B")
sinifyonetimiaciklama.grid(row=1, column=2)
sinifadigir.config(text="Sınıf Adı:")
sinifadigir.grid(row=2, column=2)
sinifadientry.grid(row=2, column=2)
islemsec.grid_remove()
sinifyonetimiaciklama = Label(fg="white", bg="#202020")
sinifadigir = Label(fg="white", bg="#202020")
sinifadientry = Entry(bd=4)
menubuton2 = Button(text="Sınıf Yönetimi", fg="white", bg="#282528", height=3, command=sinifYonetimi)
menubuton3 = Button(text="Öğrenci Yönetimi", fg="white", bg="#282528", height=3)
menubuton4 = Button(text="Konu Takibi", fg="white", bg="#282528", height=3)
menubuton5 = Button(text="İletişim", fg="white", bg="#282528", height=2)
menubuton2['font'] = menuyazilar
menubuton3['font'] = menuyazilar
menubuton4['font'] = menuyazilar
menubuton5['font'] = menuyazilar
menubuton2.grid(row=1, column=1, sticky="ew")
menubuton3.grid(row=2, column=1, sticky="ew")
menubuton4.grid(row=3, column=1, sticky="ew")
menubuton5.grid(row=4, column=1, sticky="ew")
islemsec = Label(text="Lütfen sol menüden işlem seçiniz.", bg="#202020", fg="white")
islemsec.grid(row=1, column=3)
window.mainloop()

why is the combobox shown in every frame instead of only the frame it is written in?

Im New to python Programming. At the moment im trying to build an application with multiple windows and one of those should have a combobox. I implemented the different windows and they work perfectly fine but the moment I add the Combobox to "Page Two" it gets shown in every instance no matter which page im on. I've tried switching from Pack-Manager to Grid-Manager but it doesn't change a thing.
import tkinter as tk
from tkinter import ttk, StringVar
LARGE_FONT =('Verdana',12)
class Auswertung(tk.Tk):
def __init__(self,*args, **kwargs):
tk.Tk.__init__(self,*args,**kwargs)
container = tk.Frame(self)
container.grid(row=0, column=1, padx=10, pady=10)
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,cont):
frame = self.frames [cont]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
label=tk.Label(self, text='Start Page', font=LARGE_FONT)
label.grid(row=0, column=1, padx=10, pady=10 )
button1 = tk.Button(self, text= 'Visit Page 1',
command= lambda : controller.show_frame(PageOne))
button1.grid(row=1, column=1, padx=10, pady=10)
button2 = tk.Button(self, text= 'Visit Page 2',
command= lambda : controller.show_frame(PageTwo))
button2.grid(row=2, column=1, padx=10, pady=10)
class PageOne(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
label=tk.Label(self, text='Page one', font=LARGE_FONT)
label.grid(row=0, column=1, padx=10, pady=10)
button1 = tk.Button(self, text= 'Back to Home',
command= lambda : controller.show_frame(StartPage))
button1.grid(row=1, column=1, padx=10, pady=10)
button2 = tk.Button(self, text= 'Page Two',
command= lambda : controller.show_frame(PageTwo))
button2.grid(row=2, column=1, padx=10, pady=10)
button3 = tk.Button(self, text= 'Page Two',
command= lambda : controller.show_frame(PageTwo))
button3.grid(row=3, column=1, padx=10, pady=10)
class PageTwo (tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
label=tk.Label(self, text='Page 2', font=LARGE_FONT)
label.grid(row=0, column=1, padx=10, pady=10 )
box_value=''
button1 = tk.Button(self, text= 'Back to Home',
command= lambda : controller.show_frame(StartPage))
button1.grid(row=1, column=1, padx=10, pady=10)
button2 = tk.Button(self, text= 'Go to Page 1',
command= lambda : controller.show_frame(PageOne))
button2.grid(row=2, column=1, padx=10, pady=10)
ddMenu = ttk.Combobox(textvariable = box_value ,values=[
"Big Value List I didnt want to copy"
]
)
ddMenu.grid(row=2, column=1, padx=10, pady=10)
app = Auswertung()
app.mainloop()
All 3 frames

Need help figuring out how to title the different pages in tkinter created differently without having the same title for all pages?

I am a beginner in programming in python and I have a question. With the code shown below, is it possible to give each class (which represent a different page) a different title and not a title to all the pages at once? I have looked everywhere and have been unable to find an answer. Thank you!
import tkinter as tk
# from tkinter import *
# Activate the line above when a message box is needed
class Start(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
container.pack(side="top", fill="both", expand=True)
self.title("Application")
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, PageOne):
# To add a new page, define the class below and then add the frame to the For Loop above
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self, controller):
frame = self.frames[controller]
frame.tkraise()
def get_page(self, page_class):
return self.frames[page_class]
# This is the end of the baseline and the code for each page is below:
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
Name = StringVar()
Password = StringVar()
def show_credentials(event):
instructions = tk.Label(self, text="Credentials: ")
instructions.grid(row=5, column=3, sticky="E")
names = Name.get()
passwords = Password.get()
names = tk.Label(self, text=names, bg="red", fg="white")
passwords = tk.Label(self, text=passwords, bg="Red", fg="white")
names.grid(row=6, column=3, sticky="E")
passwords.grid(row=7, column=3, sticky="E")
credentials = tk.Button(self, text="Creds")
credentials.bind("<Button-1>", show_credentials)
credentials.grid(row=4, column=3, sticky="E")
def login(event):
controller.show_frame(PageOne)
log = tk.Button(self, text="Log In")
log.bind("<Button-1>", login)
log.grid(row=4, column=4, sticky="E")
# A class can be created to compare data entered to a list to identify the user and log him/her in
welcome = tk.Label(self, text="Welcome!")
welcome.grid(row=0, column=2, sticky="E")
username = tk.Label(self, text="Username: ")
username.grid(row=2, column=2, sticky='E')
password_label = tk.Label(self, text="Password: ")
password_label.grid(row=3, column=2, sticky="E")
username_entry = tk.Entry(self, textvariable=Name)
username_entry.grid(row=2, column=3, sticky="E")
password_entry = tk.Entry(self, textvariable=Password, show="*")
password_entry.grid(row=3, column=3, sticky="E")
cancel = tk.Button(self, text="Exit", command=quit)
cancel.grid(row=4, column=2, sticky="E")
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="This page is currently under Development")
label.grid(row=0, column=0, sticky="E")
switchpage1 = tk.Button(self, text="Back", command=lambda: controller.show_frame(StartPage))
switchpage1.grid(row=1, column=0, sticky="E")
root = Start()
root.mainloop()
Here is a way to title a different window:
import tkinter as tk
root = tk.Tk()
window1 = tk.Toplevel(root)
window1.wm_title("window 1")
root.mainloop()

can any one help to find out what is missing this small program

i am trying out my first program and would appreciate if someone would tell me what is going on wrong. i wrote this program to pop up a screen with 4 choices and when i click on one of those choices it should switch screen to the next screen, please advice what did i wrote wrong because all what i am getting is the first screen then nothing when i click on the buttons thank you.
here is the program
import tkinter as tk
LARGE_FONT = ("Verdana", 12)
class SeaofBTCapp(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
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, cont):
frame = self.frames[cont]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
btn1 = tk.Button(text="", fg="white", width=400, height=240, command=lambda : controller.show_frame(PageOne))
btn1["bg"] = "white"
mi = tk.PhotoImage(file="C:\\Python\\trials\\pic1.gif")
btn1.config(image=mi)
btn1.image = mi
btn2 = tk.Button(text="", fg="white", width=400, height=240, command=lambda: controller.show_frame(PageTwo))
btn2["bg"] = "white"
mi1 = tk.PhotoImage(file="C:\\Python\\trials\\safety.gif")
btn2.config(image=mi1)
btn2.image = mi1
btn3 = tk.Button(text="", fg="white", width=400, height=240)
btn3["bg"] = "white"
mi2 = tk.PhotoImage(file="C:\\Python\\trials\\count.gif")
btn3.config(image=mi2)
btn3.image = mi2
btn4 = tk.Button(text="", fg="white", width=400, height=240)
btn4["bg"] = "white"
mi3 = tk.PhotoImage(file="C:\\Python\\trials\\about.gif")
btn4.config(image=mi3)
btn4.image = mi3
btn1.grid(row=0, column=0, columnspan=1, sticky='EW')
btn2.grid(row=0, column=1, columnspan=1, sticky='EW')
btn3.grid(row=1, column=0, columnspan=1, sticky='EW')
btn4.grid(row=1, column=1, columnspan=1, sticky='Ew')
class PageOne(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Page One!!!", font=LARGE_FONT)
label.grid(pady=10, padx=10)
button1 = tk.Button(self, text="Back to Home",
command=lambda: controller.show_frame(StartPage))
button1.grid()
button2 = tk.Button(self, text="Page Two",
command=lambda: controller.show_frame(PageTwo))
button2.grid()
class PageTwo(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Page Two!!!", font=LARGE_FONT)
label.grid(pady=10, padx=10)
button1 = tk.Button(self, text="Back to Home",
command=lambda: controller.show_frame(StartPage))
button1.grid()
button2 = tk.Button(self, text="Page One",
command=lambda: controller.show_frame(PageOne))
button2.grid()
app = SeaofBTCapp()
app.mainloop()
You have 2 problems:
First, all of your Buttons need to have the first argument 'self'. You did this in some places but you forgot it in the StartPage class.
Second, you need to layout your container. Add a pack() after you initialize it:
container = tk.Frame(self)
container.pack()

Having trouble with this method of changing and showing a new window in python

I am having quite the trouble using classes in python. The first code I used in changing and showing a new window works but too cluttered so i decided to use the class. but there might be something wrong in my code. Can you atleast see to it? Thank you. Hoping for a fast response.
import random, sys, os, rabinMiller, cryptomath
from tkinter import *
import tkinter as tk
from PIL import Image, ImageTk
from tkinter.filedialog import askopenfile
class MainFrame(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
#frame1.title("RSA Cryptosystem")
#frame1.config(bg="black")
container.columnconfigure(0, weight=1)
container.rowconfigure(0, weight=1)
self.frames = {}
for F in (StartPage, DecryptionPage, EncryptionPage, MakeKeyPage):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky=(N, W, E, S))
self.show_frame(StartPage)
def show_frame(self, cont):
frame = self.frames[cont]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self,parent)
image4 = Image.open("rsa cryptosystem logo.jpg")
photo4 = ImageTk.PhotoImage(image4)
label1 = tk.Label(self, image=photo4)
label1.grid(column=1, row=1, columnspan=3, padx=5, pady=5)
label1.image = photo4
image1 = Image.open("MAKE KEY.jpg")
photo1 = ImageTk.PhotoImage(image1)
image2 = Image.open("encryption button.jpg")
photo2 = ImageTk.PhotoImage(image2)
image3 = Image.open("decryption button.jpg")
photo3 = ImageTk.PhotoImage(image3)
button1 = tk.Button(self, compound=TOP, command=lambda: controller.show_frame(MakeKeyPage), width=338, height=338, image=photo1)
button1.grid(column=1, row=2, sticky=S, rowspan=2, padx=5, pady=5)
button1.image = photo1
button2 = tk.Button(self, compound=TOP, command=lambda: controller.show_frame(EncryptionPage), width=525, height=150, image=photo2)
button2.grid(column=2, row=2, sticky=(W, E), columnspan=2, padx=5, pady=5)
button2.image = photo2
button3 = tk.Button(self, compound=TOP, command=lambda: controller.show_frame(DecryptionPage), width=525, height=150, image=photo3)
button3.grid(column=2, row=3, sticky=(W, E), columnspan=2, padx=5, pady=5)
button3.image = photo3
class DecryptionPage(tk.Frame):
def __init__(self, parent, controller):
textframe1 = tk.Text(self, width=70, height=32).grid(column=3, row=2, rowspan=3, padx=5, pady=5, sticky=(S, E))
image5 = Image.open("INSERT PRIVATE KEY.jpg")
photo5 = ImageTk.PhotoImage(image5)
image6 = Image.open("INSERT ENCRYPTED TEXT.jpg")
photo6 = ImageTk.PhotoImage(image6)
image7 = Image.open("DECRYPT.jpg")
photo7 = ImageTk.PhotoImage(image7)
button4 = tk.Button(self, width=338, height=80, image=photo5, command=open_file)
button4.grid(column=1, row=2,columnspan=2, sticky=N)
button4.image = photo5
button5 = tk.Button(self, width=338, height=80, image=photo6, command=open_file)
button5.grid(column=1, row=3, columnspan=2, sticky=N)
button5.image = photo6
button6 = tk.Button(self, text="BACK", command=lambda: controller.show_frame(StartPage))
button6.grid(column=1, row=1, padx=5, pady=5, sticky=W)
button7 = tk.Button(self, width=338, height=338, image=photo7)
button7.grid(column=1, row=4, padx=5, pady=5, columnspan=2, sticky=S)
button7.image = photo7
class EncryptionPage(tk.Frame):
def __init__(self, parent, controller):
textframe2 = tk.Text(self, width=70, height=32).grid(column=3, row=2, columnspan=2, rowspan=3, padx=5, pady=5, sticky=(S, E))
image8 = Image.open("INSERT PUBLIC KEY.jpg")
photo8 = ImageTk.PhotoImage(image8)
image9 = Image.open("ENCRYPT.jpg")
photo9 = ImageTk.PhotoImage(image9)
button8 = tk.Button(self, width=338, height=80, image=photo8, command=open_file)
button8.grid(column=1, row=2,columnspan=2, sticky=N)
button8.image = photo8
button10 = tk.Button(self, text="BACK", command=lambda: controller.show_frame(StartPage))
button10.grid(column=1, row=1, padx=5, pady=5, sticky=W)
button9 = tk.Button(self, width=338, height=338, image=photo9)
button9.grid(column=1, row=4, padx=5, pady=5, columnspan=2, sticky=S)
button9.image = photo9
receivename = StringVar()
receivename_entry = tk.Entry(self, width=85, textvariable=receivename).grid(column=4, row=1, padx=5, pady=5, sticky=(W, E))
label4 = tk.Label(self, text="TO: ").grid(column=3, row=1, padx=5, pady=5, sticky=W)
class MakeKeyPage(tk.Frame):
def __init__(self, parent, controller):
keyname = StringVar()
phone = StringVar()
keyname_entry = tk.Entry(self, width=15, textvariable=keyname)
keyname_entry.grid(column=2, row=2, sticky=E, padx=5, pady=5)
label2 = tk.Label(self, text="Key Name: ")
label2.grid(column=1, row=2, sticky=W, padx=5, pady=5)
label3 = tk.Label(self, text="Key Type: ")
label3.grid(column=1, row=3, sticky=W, padx=5, pady=5)
button12 = tk.Button(self, text="BACK", command=lambda: controller.show_frame(StartPage)).grid(column=1, row=1, padx=5, pady=5, sticky=W)
prime = tk.Radiobutton(self, text="Prime", variable=phone, value='prime').grid(column=1, row=4, sticky=(W, E))
luckyprime = tk.Radiobutton(self, text="Lucky Prime", variable=phone, value='luckyprime').grid(column=2, row=4, sticky=(W, E))
button11 = tk.Button(self, text="Generate Keys").grid(column=1, row=5, columnspan=2, sticky=(W, E))
app = MainFrame()
app.mainloop()

Resources