Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.get()在python中接受两个参数_Python_Tkinter - Fatal编程技术网

.get()在python中接受两个参数

.get()在python中接受两个参数,python,tkinter,Python,Tkinter,所以,我从sublime text 2切换到Pycharm,它一直告诉我.get()在sublime中工作正常时接受2个参数(1个给定)。有人能帮我一下吗,我找不到解决办法,但我可能只是没找到运气。这是我的密码: import Tkinter import codecs import json def write(): # def function to create file.json with encoding print('Creating new text file')

所以,我从sublime text 2切换到Pycharm,它一直告诉我.get()在sublime中工作正常时接受2个参数(1个给定)。有人能帮我一下吗,我找不到解决办法,但我可能只是没找到运气。这是我的密码:

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()

您需要为get()方法提供索引。我假设您希望在文本框中获取所有文本

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

你得到的是哪一行的错误?你能粘贴完整的回溯吗?还有,什么是E1?E1和T1是什么类型?我刚刚为你们发布了全部代码。我忘了我没有说明变量类型以及它们的来源。您的错误在哪一行?我还忘了列出我的错误是什么。\u。它位于edit_text()中。“new_line=(T1.get())”end-1c可能是最好的选择,因为它不固定换行符。这就解决了它!谢谢你,如果你有任何其他的想法来改进我的代码,我会很感激的,但如果没有,那很冷