Bottom Page

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.
Quote
#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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [PyQt] pyqt5 comobox insert into mysql Weballround 2 134 Jan-11-2019, 05:56 AM
Last Post: Weballround
  Insert color in tkinter automatically Dwimmerlaik 4 191 Jan-07-2019, 07:10 PM
Last Post: Dwimmerlaik
  GUI insert textbox value into a Class dimvord 0 339 Jul-04-2018, 06:49 PM
Last Post: dimvord
  [Tkinter] insert table columns data in different textboxes dimvord 4 530 Jun-15-2018, 07:40 AM
Last Post: dimvord
  Using a class to create instances of Tkinter Toplevel() windows nortski 2 1,281 Mar-27-2018, 11:44 AM
Last Post: nortski
  tkinter scrolledtext formatting Lux 1 1,175 Aug-14-2017, 12:39 AM
Last Post: Larz60+

Forum Jump:


Users browsing this thread: 1 Guest(s)