Last active
December 14, 2015 01:59
-
-
Save farces/5010759 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tkinter import * | |
class App: | |
def __init__(self, master): | |
frame = Frame(master) | |
frame.pack() | |
self.start = Button(frame, text = "Begin", command = self.start_up) | |
self.start.pack() | |
self.end = Button(frame, text = "End", command = frame.quit) | |
self.end.pack() | |
def start_up(self): | |
temp = New_window() | |
class New_window: #Manages the new window | |
def __init__(self): | |
self.top = Toplevel() # top should be a member of New_window, so add self. | |
self.top.title("Back and forth!") | |
self.message = "Hit Previous or Next" | |
#removed pack() from here, only need to pack() tk widgets like textboxes and buttons etc. | |
# Create buttons | |
# needs to be self.top and self.top.destroy | |
self.quit = Button(self.top, text = "QUIT", command=self.top.destroy) | |
self.quit.pack(side=LEFT) | |
#needs to be self.top | |
self.prev = Button(self.top, text = "Previous", command=self.prev) | |
self.prev.pack(side=LEFT) | |
#needs to be self.top | |
self.nxt = Button(self.top, text = "Next", command=self.nxt) | |
self.nxt.pack(side=LEFT) | |
# Create text box | |
# Renamed to textbox, and top changed to self.top | |
self.textbox = Text(self.top, width = 20, height = 2, wrap = WORD) | |
self.textbox.grid(row = 1, column = 1) | |
self.textbox.pack() # have to pack() the textbox here | |
self.mess_update() # added this to update the textbox with the initial | |
# "Hit Previous or Next" message | |
def nxt(self): | |
self.message = "Moving forward" # changed to self.message | |
self.mess_update() # added brackets, without them the function isn't called | |
def prev(self): | |
self.message = "Let's go back" # changed to self.message | |
self.mess_update() # added brackets, without them the function isn't called | |
def mess_update(self): | |
# renamed to self.textbox | |
self.textbox.delete(0.0, END) | |
self.textbox.insert(0.0, self.message) # changed to self.message | |
root = Tk() | |
app = App(root) | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment