user interface - Python GUI - Insert text to text box -


i got python guis , testing different things, since seems me learn easier (trial , error). 1 thing trying inserting message different class. can say, don't know use for, trying sake of trying.

# hello world # displays "hello world!" in text box.  tkinter import *  class myclass(object):     def mymethod():         print("hello world!")  class application(frame):     """ gui application can reveal secret of longevity. """     def __init__ (self, master):         super(application, self).__init__(master)         self.grid()         self.createwidgets()      def createwidgets(self):         # create text box         self.txtbox = text(self, width = 300, height = 300, wrap = word)         self.txtbox.grid(row = 0, column = 0, sticky = w)          # display message         message = myclass.mymethod         self.txtbox.insert(0.0, message)  # main root = tk() root.title("my title") root.geometry("500x500")  app = application(root)  root.mainloop() 

when run .py file gui , box says <function myclass.mymethod @ 0x0000000002a1c6a8> - if not mistaken means mymethod stored in memory.

so used message = myclass.mymethod() thinking output "hello world!" - instead error. @ first along lines of object.init doesn't take parameters or (apologies because wasn't able recreate error) - getting tkinter.tclerror: wrong # args: should "43128536.43105360 insert index chars ?taglist chars taglist...?

is possible have "hello world!" class, print in gui text box?

also, while looking on code, curious. purpose of app = application(root)? when don't have there, blank gui. however, don't see calls app other setting equal application(root).

you adding function textbox. call function , use return value of it.

    message = myclass.mymethod()     self.txtbox.insert(1.0, message) 

myclass need modification. return string instead of print it.

class myclass(object):     def mymethod():         return "hello world!" 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -