Sergio
Sergio

Reputation: 53

.get() taking two arguments in python

So, I switched from sublime text 2 to Pycharm, and it keeps telling me that .get() takes 2 arguments (1 given) when it worked fine in sublime. Can someone help me out here, I cannot find a solution to this, but I'm probably just not having luck finding it. Here's my code:

import Tkinter
import codecs
import json


def write():  # def function to create file.json with encoding
    print('Creating new text file')
    name_with_ext = (E1.get()) + '.json'  # name of file coerced with +.json
    file_name = E1.get()
    try:
        with codecs.open(name_with_ext, 'a', 'utf8') as f:
            f.write(json.dumps(file_name, sort_keys=True, ensure_ascii=False))  # encode
    except:
        print('Something went wrong! Can\'t tell what?')
        Tkinter.sys.exit(0)  # quit Python


def edit_gui():
    global T1
    global name_with_ext
    name_with_ext = (E1.get()) + '.json'  # name of file coerced with +.json
    # gui for editing text
    k = Tkinter.Tk()
    T1 = Tkinter.Text(k, width=100, height=50)
    T1.pack(side=Tkinter.RIGHT)
    b3 = Tkinter.Button(k, text='Text to add:', command=edit_text)
    b3.pack(side=Tkinter.BOTTOM)
    k.mainloop()


def edit_text():
    print('Editing text')
    new_line = (T1.get())  # new entry variable
    with open(name_with_ext, "r+") as f:
        old = f.read()
        f.seek(0)
        if old is True:
            f.write(old + ' ' + new_line)
        else:
            f.write(new_line)


# define mGUI for program
root = Tkinter.Tk()
E1 = Tkinter.Entry(root, bd=5)
E1.pack(side=Tkinter.RIGHT)
B1 = Tkinter.Button(root, text='create file:', command=write)
B1.pack(side=Tkinter.LEFT)
B2 = Tkinter.Button(root, text='edit file:', command=edit_gui)
B2.pack(side=Tkinter.LEFT)
root.mainloop()
write()

Upvotes: 0

Views: 1366

Answers (1)

galaxyan
galaxyan

Reputation: 6111

you need to give index for get() method. I assume you want to get all text in text box.

new_line = (T1.get("1.0",'end-1c'))

Upvotes: 2

Related Questions