我曾經有過這段代碼的問題,它是GCSE模擬的一部分,我目前已完成工作代碼(僅限文本),但我想擴展它以便它有一個很好的GUI。我在代碼中更新我的句子變量時遇到了一些問題。任何人有任何建議,請解釋我如何解決它。Python Tkinter 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()
「不工作」不是對問題的信息描述。請修改您的問題以包含預期和實際行爲以及任何錯誤消息。 – user2085282
我注意到你沒有關閉你的文件閱讀器,這可能不是問題,但可以提出一些例外 – Adi
「在代碼中更新我的句子變量」可能對你有意義,但我不知道這意味着什麼。請描述一些具體的投入,實際產出,以及實際產出與預期的不同。 –