Nov-14-2017, 11:09 PM
1. text_box need to be part of the class. don't make a new one each time method is called.
put in __init__
put in __init__
self.text_box = Text(self.root, bg = 'blue', fg = 'white') self.text_box.pack(side=LEFT)here another example
import tkinter as tk # just inherit it to make custom tk.Text class Custom_Console(tk.Text): def __init__(self, master): tk.Text.__init__(self, master, bg = 'blue', fg = 'white') self.pack(side = tk.LEFT) #custom methods def write(self, content): self.insert(tk.END, content) def writeln(self, content): self.insert(tk.END, content + '\n') def main(): root = tk.Tk() app = Custom_Console(root) app.insert(tk.END, "0 ") app.write("1 ") app.writeln("2") app.writeln("Here we go") app.mainloop() if __name__ == '__main__': main()
99 percent of computer problems exists between chair and keyboard.