Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.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
Python Tkinter Gui不工作_Python_Tkinter_Tk_Python 3.3 - Fatal编程技术网

Python Tkinter Gui不工作

Python Tkinter Gui不工作,python,tkinter,tk,python-3.3,Python,Tkinter,Tk,Python 3.3,这段代码是GCSE模拟的一部分,我在不久前就遇到了一个问题,目前我已经完成了工作代码(仅限文本),但我想扩展它,使它有一个漂亮的GUI。我在更新代码中的语句变量时遇到了一些问题。任何对我有任何建议的人,请解释我如何解决它 #GCSE TASK WITH GUI import tkinter from tkinter import * from tkinter import ttk var_sentence = ("default") windo

这段代码是GCSE模拟的一部分,我在不久前就遇到了一个问题,目前我已经完成了工作代码(仅限文本),但我想扩展它,使它有一个漂亮的GUI。我在更新代码中的语句变量时遇到了一些问题。任何对我有任何建议的人,请解释我如何解决它

    #GCSE TASK WITH GUI
    import tkinter
    from tkinter import *
    from tkinter import ttk

    var_sentence = ("default")

    window = tkinter.Tk()
    window.resizable(width=FALSE, height=FALSE)
    window.title("Sentence")
    window.geometry("400x300")
    window.wm_iconbitmap("applicationlogo.ico")

    file = open("sentencedata.txt","w")
    file = open("sentencedata.txt","r")

    def update_sentence():
        var_sentence = sentence.get()


    def submit():
        file.write(sentence)
        print ("")

    def findword():
        messagebox.showinfo("Found!")
        print ("Found")


    sentencetext = tkinter.Label(window, fg="purple" ,text="Enter Sentence: ")
    sentence = tkinter.Entry(window)
    sentencebutton = tkinter.Button(text="Submit", fg="red" , command=update_sentence)

    findword = tkinter.Label(window, fg="purple" ,text="Enter Word To Find: ")
    wordtofind = tkinter.Entry(window)
    findwordbutton = tkinter.Button(text="Find!", fg="red" ,command=findword)


    usersentence = sentence.get()
    usersentence = tkinter.Label(window,text=sentence)


    shape = Canvas (bg="grey", cursor="arrow", width="400", height="8")
    shape2 = Canvas (bg="grey", cursor="arrow", width="400", height="8")

    #Packing & Ordering Moduales
    sentencetext.pack()
    sentence.pack()
    sentencebutton.pack()

    shape.pack()

    findword.pack()
    wordtofind.pack()
    findwordbutton.pack()
    usersentence.pack()

    shape2.pack()

    window.mainloop()

如果我没有弄错您的问题,您希望在
user句子
标签中显示输入的文本

update\u-sen句()
函数更改为如下所示,将达到所需效果

def update_sentence():
    var_sentence = sentence.get()
    usersentence.config(text=var_sentence)

user句子
永远不会更新,因为在程序启动时只设置一次。这是问题所在。

“不工作”不是问题的信息性描述。请编辑您的问题,以包括预期和实际行为以及任何错误消息。我注意到您没有关闭文件读取器,这可能不是问题所在,但可能会引发一些异常“在代码中更新我的句子变量”可能对您有意义,但我不知道这意味着什么。请描述一些具体的输入、实际输出,以及实际输出与您期望的不同。谢谢,您已经解决了我的问题。我已经寻找了很长一段时间,您终于解决了它。再次感谢。首先,很难弄清楚实际问题是什么,所以将来当你发布问题时,请更详细地说明问题是什么。谢谢