我已经将一个字符串放入Tkinter的Label中,并且在字符串末尾添加了[[]]

时间:2019-05-17 14:31:53

标签: python-3.x tkinter

Image showing my computer screen and all the outputs我有一个字符串要放入Label中,并在其末尾添加'[]',我正在使用一种怪异的方式将它从一个pickle保存文件中转换为字符串,其中有一个循环重复字符串的长度,并从字符串的第n个字母开始并将其添加到另一个字符串中

我在经过奇怪的转换代码后将其打印到了外壳程序中,但是它不包含'[]'。除此之外,我还尝试了'.replace(“ []”,“”)'方法,但这并没有删除双方括号。这困扰了我好几个小时,我进行了一次广泛的谷歌搜索以尝试找到遮阳篷

P.S学生姓名在前面提到过,但仅仅是:

studentname = ""

第1节:

global studentname
        Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
        filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file
        pickleoff = open(filename, "rb")
        master = pickle.load(pickleoff)
        pickleoff.close()
        rar = master[0]
        for i in range(len(master[0])):
            studentname = studentname + rar[i]
        print(studentname)

第2节:

def gui():
        swin = tkinter.Tk()
        swin.geometry('600x600')
        swin.title('Home')
        global studentname
        name = Label(swin, text = studentname)

如果学生名字叫Bob,我会期望: 鲍勃 但是我实际上正在得到: 鲍勃[]

0 个答案:

没有答案