#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Posts
    85
    Rep Power
    2

    [Python 2.7 + Tkinter] Export .txt file not works, Error Found!


    Hey Python GUI Programmers and Software Developers...

    I try to create an simple test program, just you can typ text into an 'Scrolled Text Bar'....
    But i want to make the in scrolled text typed text exportible as an .txt file with given it an
    filename...


    So this is my script, writted in python 2.7 on an older windows system:
    Code:
    from Tkinter import *
    from ttk import *
    from ScrolledText import *
    
    class NoteBook(Frame):
    
        def __init__(self, master=None):
    
            self.master = master
    
            Frame.__init__(self, master)
    
            self.init_window()
    
        def init_window(self):
    
            self.master.title("NoteBook")
    
            self.pw = PanedWindow(self.master, orient = VERTICAL)
            self.pw.pack(padx = 10, pady = 2, side = BOTTOM)
    
            self.nb = Notebook(self.pw, height = 480, width = 640)
            self.pw.add(self.nb)
    
            self.nb_frame1 = Frame(self.nb)
            self.nb.add(self.nb_frame1, text = "Tools")
    
            self.nb_frame2 = Frame(self.nb)
            self.nb.add(self.nb_frame2, text = "Modifiers")
    
            self.nb_frame3 = Frame(self.nb)
            self.nb.add(self.nb_frame3, text = "Options")
    
            self.nb_frame4 = Frame(self.nb)
            self.nb.add(self.nb_frame4, text = "Textures")
    
            self.nb_frame5 = Frame(self.nb)
            self.nb.add(self.nb_frame5, text = "Materials")
            
            self.nb.pack(fill = BOTH, expand = True)
    
    
    
            # Call Frame1 Tab
    
            self.e = Entry(self.nb_frame1)
            self.e.pack(fill = X, side = TOP)
    
            self.b = Button(self.nb_frame1, text = "Send")
            self.b.pack(fill = X, side = TOP)
    
    
    
            # Call Frame2 Tab
    
            self.l = Label(self.nb_frame2)
            self.l.pack(padx = 10, pady = 10)
    
    
            self.st = ScrolledText(self.l, wrap = WORD)
            self.st.insert(END, str(''))
            self.st.pack(fill = BOTH, expand = True)
    
            self.tb = Entry(self.l)
            self.tb.pack(fill = X, side = TOP)
    
            self.eb = Button(self.l, text = "Export", command = self.Export)
            self.eb.pack(fill = X, expand = True)
    
    
    
    
    
            # Call Frame3 Tab
    
            self.s1 = Scale(self.nb_frame3, from_=0, to=4, orient = HORIZONTAL)
            self.s2 = Scale(self.nb_frame3, from_=0, to=100, orient = HORIZONTAL)
    
            self.s1.pack(fill = X, side = TOP)
            self.s2.pack(fill = X, side = TOP)
    
    
        def Export(self):
    
            filename = self.tb.get()
            var = self.st.get()
    
            with open(filename + '.txt', 'w') as textfile:
    
                textfile.write(var + '\n')
                textfile.close()
    
    
    
    
    
    if __name__ == "__main__":
    
        root = Tk()
        NoteBook(root)
        root.mainloop()


    If i run my script and try to export the scrolled text as an .txt file yet, i get an error...


    So this is my error:
    Exception in Tkinter callback
    Traceback (most recent call last):
    File "C:\Python27\lib\lib-tk\Tkinter.py", line 1541, in __call__
    return self.func(*args)
    File "C:\Documents and Settings\Eigenaar\Bureaublad\jamie\Python\Python Tkinter\Tkinter Notebook.py", line 86, in Export
    var = self.st.get()
    TypeError: get() takes at least 2 arguments (1 given)


    So can anyone fix my problem yet, to correct my code, just i can expiriment
    with it ?...., thanks for help!.....

    Jamie.
    Last edited by JamieVanCadsand; April 25th, 2018 at 04:25 AM.
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,974
    Rep Power
    510
    I think you have to tell the scrolled text widget from where you want the text. Sometimes daniweb is useful, here's a link to some documentation. Neither ttk nor ScrolledText are available to me this week.
    https://www.daniweb.com/programming/...-widget-python
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Posts
    667
    Rep Power
    40
    Yes, I like effbot's documentation. Look up the Text widget as Scrolledtext is a Text with a scrollbar The Tkinter Text Widget

IMN logo majestic logo threadwatch logo seochat tools logo