Hack Forums
[Python] tkinter Error/ insert text from another function help - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] tkinter Error/ insert text from another function help (/showthread.php?tid=6032020)



tkinter Error/ insert text from another function help - h0lyl337 - Dec 11, 2019

this is the code guys just tryna make the update text function work the error i get is "AttributeError: 'App' object has no attribute 'textbox'


Code
import os
import requests
import json
import hashlib
import time

from tkinter import *
from tkinter import ttk
import threading


class App(threading.Thread):

   def __init__(self):
       threading.Thread.__init__(self)
       self.start()

   def callback(self):
       self.root.quit()

   def run(self):
       self.root = Tk()
       self.root.geometry('500x300')
       title = Label(self.root, text='H0lyAV v0.1')
       title.pack()
       tabocontrol = ttk.Notebook(self.root)
       tab1 = ttk.Frame(tabocontrol)
       tab2 = ttk.Frame(tabocontrol)
       tabocontrol.add(tab1, text='Main')
       tabocontrol.add(tab2, text='Settings')
       self.textbox = Text(tab1, height=10, width=100)
       self.textbox.pack(side=BOTTOM)
       self.text = Text(self.textbox)
       b1 = Button(tab1, text='asdf')
       b1.pack(anchor='w')
       self.root.protocol("WM_DELETE_WINDOW", self.callback)
       tabocontrol.pack(expand=1, fill="both")
       self.root.mainloop()

   def updatetext(self):
       self.textbox.insert(INSERT, 'ASDF')

if __name__ == '__main__':
   App = App()
   App.updatetext()



RE: tkinter _error_/ insert text from another function help - Nachfolger - Dec 11, 2019

Nothing ever calls App.run, thus, self.textbox isn't initialized.


RE: tkinter _error_/ insert text from another function help - h0lyl337 - Dec 11, 2019

(Dec 11, 2019 09:18 AM)Nachfolger Wrote:  Nothing ever calls App.run, thus, self.textbox isn't initialized.

how would you fix this bro? if i call app.run the gui starts acting funky.