Python Forum

Full Version: Tkinter Gui ScrolledText Insert From Different Class
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey all, I feel like I'm pretty close, but I cannot seem to figure out why my calls to the function
are 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.textBox=textBoxClass(self.parent) #saving the instance 

	def Window(self): 
		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):
		# 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."
class textBoxClass(): #removed tkst.ScrolledText in class call because instance was created in textDropIn
	def __init__(self,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):

def main(): 
	root =tk.Tk()

if __name__=='__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.
you have a bad recursion issue here:
It hurts to try and follow.

instead of using 'some', suggest you preceded function calls and shared variables with an abbreviation of
the class they belong to.