Python Forum
Tkinter Gui ScrolledText Insert From Different Class
Thread Rating:
  • 1 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter Gui ScrolledText Insert From Different Class
#1
Hey all, I feel like I'm pretty close, but I cannot seem to figure out why my calls to the function
TextWindowWrite
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.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.
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] How to insert data json to treeview tkinter? Shakanrose 8 4,217 Jan-19-2023, 03:58 PM
Last Post: Shakanrose
Lightbulb Using Tkinter With Concurrent.Futures / ThreadPoolExecutor Class AaronCatolico1 1 1,420 Dec-14-2022, 08:01 PM
Last Post: deanhystad
Lightbulb [Tkinter] Tkinter Class Import Module Issue AaronCatolico1 6 2,981 Sep-06-2022, 03:37 PM
Last Post: AaronCatolico1
  [Tkinter] Redirecting all print statements from all functions inside a class to Tkinter Anan 1 2,603 Apr-24-2021, 08:57 AM
Last Post: ndc85430
  tkinter moving an class object with keybinds gr3yali3n 5 3,185 Feb-10-2021, 09:13 PM
Last Post: deanhystad
  tkinter| listbox.insert problem Maryan 3 3,441 Sep-29-2020, 05:34 PM
Last Post: Yoriz
  [Tkinter] Troubles with accessing attr from other class zarize 3 2,579 Aug-20-2020, 06:05 PM
Last Post: deanhystad
  [Tkinter] Use function from other class (Tkinter) zarize 8 4,705 Aug-17-2020, 09:47 AM
Last Post: zarize
  tkinter scrolledtext formatting Lux 2 6,275 Feb-17-2020, 06:59 PM
Last Post: Rama2020
  Unable fetch fucntion data in class in tkinter jenkins43 2 3,835 Nov-30-2019, 09:47 PM
Last Post: jenkins43

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020