Im wechseln versuchen, mich selbst zu lehren, wie tkinter zu verwenden, und ich fand youtube einen nützlichen Code durch, die ich voll und ganz verstehen nicht wirklich. Würde es schätzen, wenn einige mir helfen könnten, es zu verstehen. So bezeichnet die Dinge, die ich nicht verstand, mit **Tkinter! Zu verstehen, wie Frames
import tkinter as tk # why not from tkinter import? **
class SampleApp(tk.Tk): tk.TK**
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
# the container is where we'll stack a bunch of frames
# on top of each other, then the one we want visible
# will be raised above the others
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 (StartPage, PageOne, PageTwo):
page_name = F.__name__
frame = F(container, self) **
self.frames[page_name] = frame **
# put all of the pages in the same location;
# the one on the top of the stacking order
# will be the one that is visible.
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame("StartPage")
def show_frame(self, page_name):
'''Show a frame for the given page name'''
frame = self.frames[page_name]
frame.tkraise() **
class StartPage(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent) **
self.controller = controller **
label = tk.Label(self, text="This is the start page",
font=TITLE_FONT)
label.pack(side="top", fill="x", pady=10)
button1 = tk.Button(self, text="Go to Page One",
command=lambda: controller.show_frame("PageOne"))
button2 = tk.Button(self, text="Go to Page Two",
command=lambda: controller.show_frame("PageTwo"))
button1.pack()
button2.pack()
könnten Sie bitte den YouTube-Link teilen? –
@BryanOakley Falls Sie noch suchen, ich habe gesehen, [diese] (https://www.youtube.com/watch?v=jBUpjijYtCk) Tutorial, das Sie den Code aus dem [ursprünglichen Frage] verwendet (http: // stackoverflow.com/a/7557028/3826759), obwohl er sagt, woher es kommt. Es gibt auch [diese] (https://pythonprogramming.net/plotting-live-bitcoin-price-data-tkinter-matplotlib/). –
@double_j: Ja, ich fand es schon eine Weile her, aber dank. Ich habe diesen anderen Link, den du angegeben hast, nicht gesehen. Ich habe die ursprüngliche Antwort verbessert, damit ich sagen kann, wer mit meinem Code begonnen hat und wer mit diesem Video-Tutorial angefangen hat. Dieser Code hat ein Eigenleben angenommen, das in vielen neuen Fragen auftaucht. –