Jan-08-2019, 06:45 PM
(This post was last modified: Jan-08-2019, 06:46 PM by whisperquiet.)
Hey all, I feel like I'm pretty close, but I cannot seem to figure out why my calls to the function
TextWindowWriteare not going through and I would greatly appreciate help with this code.
from tkinter import ttk import tkinter as tk import tkinter.scrolledtext as tkst class someGui(tk.Tk): def __init__(self,parent): self.parent=parent self.Window() self.textBox=textBoxClass(self.parent) #saving the instance def Window(self): self.parent.configure(bg='white') self.parent.geometry("1000x500") self.parent.title("Example Window") self.someFrame = ttk.Frame(self.parent) self.someFrame.grid(row=0, column=0, sticky='nesw') #changed sticky definition for tk requirements textBoxSeparate=textBoxClass(self.parent) # the initial inclusion of the textbox in the frame self.someFunction() #no input needed def someFunction(self): #otherstuff # self.textBox.textDropIn() #there is no parent attribute in textDropIn, so I removed it # self.textBox.insert(tk.INSERT, "Some test text.") #split call to two lines and changed to tk.INSERT textVar="This is a test." self.textBox.TextWindowWrite(textVar) class textBoxClass(): #removed tkst.ScrolledText in class call because instance was created in textDropIn def __init__(self,parent): self.root=parent # super().__init__() #kept receiving TypeError: object.__init__() takes no arguments, thus removed args self.textDropIn() #removed parent attribute from function call def textDropIn(self): #removed parent attribute from definition self.someText = tkst.ScrolledText(master=self.root, wrap=tk.WORD, width=50, height=20) self.someText.grid(row=0, column=4, rowspan=7, columnspan=4, pady=20, padx=20) def TextWindowWrite(self,textToWrite): self.someText.insert(tk.INSERT,textToWrite) def main(): root =tk.Tk() sg=someGui(root) root.mainloop() if __name__=='__main__': main()My entire goal here is to update the text window created with ScrolledText so that I can write text based on the operations of other functions in a different class. I am having trouble calling the functions from a different class correctly.