My code basically does this:
Which is clearly not what I want to try. For further clarification I would like my window to look similar to this:
from tkinter import *
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
class Encoding(tk.Tk):
def __init__(self, parent, *args, **kwargs):
tk.Frame.__init__(self, parent, *args, **kwargs)
self.mode = StringVar()
## If I remove the next line it breaks it entirely.
self.encoding_frame = ttk.Frame(parent)
self.encrypt = ttk.Radiobutton(self.encoding_frame, text='Encrypt', variable=self.mode, value='encrypt')
self.decrypt = ttk.Radiobutton(self.encoding_frame, text='Decrypt', variable=self.mode, value='decrypt')
self.encrypt.grid(column=0, row=0, ipadx=2, sticky=W)
self.decrypt.grid(column=0, row=1, ipadx=2, sticky=W)
self.encoding_frame.grid(column=0, columnspan=3, row=2, sticky=S)
class MainApplication(tk.Frame, Encoding):
# Create a main frame here.
# Would like frames to be nested within this frame. This seems redundant but nesting with a main
# frame allows for consistent themes, and gives additional control of layout between subframes.
# Inheritance is confusing.
def __init__(self, parent, *args, **kwargs):
tk.Frame.__init__(self, parent, *args, **kwargs)
self.main_frame = ttk.LabelFrame(parent, text="Main Window", width=500, height=500)
self.main_frame['borderwidth'] = 3
self.main_frame['relief'] = 'raised'
self.main_frame.grid(column=0, row=0)
self.encoding = Encoding(self)
## I wrote the following line hoping that I could have main_frame become the parent frame.
self.encoding.encoding_frame = ttk.LabelFrame(self.main_frame)
if __name__ == "__main__":
app = MainApplication(root)
root.mainloop()
I am clearly not getting something right. The whole reason I rewrote the program is so that I could gain a greater understanding/confidence with object oriented code. I am hoping that I can get better insight with this, so any help would be amazing.