我的代码基本上是这样做的:
<< img src =“ https://image.soinside.com/eyJ1cmwiOiAiaHR0cHM6Ly9pLmltZ3VyLmNvbS9zbWhWQ09PLnBuZyJ9” alt =“我的问题”>
显然不是我想要尝试的。为了进一步说明,我希望我的窗口看起来像这样:
“ >>
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()
我显然做错了什么。我重写该程序的全部原因是为了使我对面向对象的代码有更大的了解/信心。我希望我能对此有所了解,所以任何帮助都会很棒。
我的代码基本上是这样做的:这显然不是我想要尝试的。为了进一步说明,我希望我的窗口看起来像这样:from tkinter import *将tkinter as tk from ...
您的代码有几个问题。