Python 编辑后保存项目
我创建了一个简单的GUI应用程序,用于在学习新语言时管理未知单词。这个名为词汇表的应用程序是用C#编写的,它将单词从XML文档加载/保存到XML文档中。由于我最近从Windows切换到Linux,我正在使用Python重写应用程序 然而,我在编辑一个单词后保存它时遇到了麻烦 以下是我的C#方法: …下面是我的Python函数:Python 编辑后保存项目,python,tkinter,Python,Tkinter,我创建了一个简单的GUI应用程序,用于在学习新语言时管理未知单词。这个名为词汇表的应用程序是用C#编写的,它将单词从XML文档加载/保存到XML文档中。由于我最近从Windows切换到Linux,我正在使用Python重写应用程序 然而,我在编辑一个单词后保存它时遇到了麻烦 以下是我的C#方法: …下面是我的Python函数: def save_item(self): if len(self.listBox.curselection()) > 0: word =
def save_item(self):
if len(self.listBox.curselection()) > 0:
word = self.find_word(self.listBox.curselection())
word.wordorphrase = self.get_word()
word.explanation = self.get_explanation()
word.translation = self.get_translation()
word.example = self.get_example()
self.listBox.curselection() = self.get_word()
self.read_only_ON()
else:
messagebox.showinfo('Notification', 'You have not selected any word!')
self.save_all()
self.word_count()
应用程序无法启动,因为:
/usr/bin/python3.5 /home/cali/PycharmProjects/Vocabulary/Vocabulary.py
File "/home/cali/PycharmProjects/Vocabulary/Vocabulary.py", line 232
self.listBox.curselection() = self.get_word()
^
SyntaxError: can't assign to function call
Process finished with exit code 1
另外,当我注释掉那一行时,我得到了另一个错误:
/usr/bin/python3.5 /home/cali/PycharmProjects/Vocabulary/Vocabulary.py
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/lib/python3.5/tkinter/__init__.py", line 1553, in __call__
return self.func(*args)
File "/home/cali/PycharmProjects/Vocabulary/Vocabulary.py", line 227, in save_item
word.wordorphrase = self.get_word()
AttributeError: 'NoneType' object has no attribute 'wordorphrase'
有人能帮我吗?我不知道如何访问:
listView1.选择编辑项[0]。文本
另外,如果您查看一下我的全部代码,可能会有所帮助:
# Vocabulary.py
# GUI program to manage unknown words
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
import xml.etree.ElementTree as ET
import os
class Word:
def __init__(self, wordorphrase = None, explanation = None, translation = None, example = None):
self.wordorphrase = wordorphrase
self.explanation = explanation
self.example = example
self.translation = translation
class Vocabulary(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.master = master
self.master.resizable(width = False, height = False)
self.master.title('Vocabulary')
self.create_widgets()
self.words = []
self.load_words()
def on_closing(self):
self.save_all()
if messagebox.askokcancel("Quit", "Do you want to quit?"):
self.master.destroy()
def create_widgets(self):
self.buttons_frame = Frame(self.master)
self.buttons_frame.grid(row = 10, sticky = W)
self.search_frame = Frame(self.master)
self.search_frame.grid(row = 1, sticky = W, columnspan = 2)
self.comboBox = ttk.Combobox(self.search_frame,
width = 3)
self.comboBox.grid(row = 0, column = 14, sticky = W)
self.comboBox['values'] = ( 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' )
self.btn_Add = Button(self.buttons_frame,
text = 'Add',
command = self.add_item)
self.btn_Add.grid(row = 0, sticky = W)
self.btn_Remove = Button(self.buttons_frame,
text = 'Remove',
command = self.remove_item)
self.btn_Remove.grid(row = 0, column = 1, sticky = W)
self.btn_Edit = Button(self.buttons_frame,
text = 'Edit',
command = self.edit_item)
self.btn_Edit.grid(row = 0, column = 2, sticky = W)
self.btn_Save = Button(self.buttons_frame,
text = 'Save',
command = self.save_item)
self.btn_Save.grid(row = 0, column = 3, sticky = W)
self.btn_Refresh = Button(self.buttons_frame,
text = 'Refresh',
command = self.refresh_all)
self.btn_Refresh.grid(row = 0, column = 4, sticky = W)
self.lblSearch = Label(self.search_frame, text = 'SEARCH: ')
self.lblSearch.grid(row = 0, column = 5, sticky = W)
self.txt_Search = Text(self.search_frame,
height = 1,
width = 70)
self.txt_Search.grid(row = 0, column = 6, columnspan = 3, sticky = W)
self.lblWordsOrPhrases = Label(self.master, text = 'WORDS/PHRASES:')
self.lblWordsOrPhrases.grid(row = 2, column = 0)
self.lblWordOrPhrase = Label(self.master, text = 'Word or phrase:')
self.lblWordOrPhrase.grid(row = 2, column = 1, sticky = W)
self.listBox = Listbox(self.master,
selectmode='extended',
height = 34,
width = 38)
self.listBox.grid(row = 3, column = 0, rowspan = 7, sticky = W)
self.listBox.bind('<<ListboxSelect>>', self.selectedIndexChanged)
self.txt_WordOrPhrase = Text(self.master,
height = 1,
width = 40)
self.txt_WordOrPhrase.grid(row = 3, column = 1, sticky = N)
self.lblExplanation = Label(self.master, text = 'Explanation:')
self.lblExplanation.grid(row = 4, column = 1, sticky = W)
self.txt_Explanation = Text(self.master,
height = 10,
width = 40)
self.txt_Explanation.grid(row = 5, column = 1, sticky = N)
self.lblTranslation = Label(self.master, text = 'Translation:')
self.lblTranslation.grid(row = 6, column = 1, sticky = W)
self.txt_Translation = Text(self.master,
height = 10,
width = 40)
self.txt_Translation.grid(row = 7, column = 1, sticky = N)
self.lblExamples = Label(self.master, text = 'Example(s):')
self.lblExamples.grid(row = 8, column = 1, sticky = W)
self.txt_Example = Text(self.master,
height = 10,
width = 40)
self.txt_Example.grid(row = 9, column = 1, sticky = S)
def load_words(self):
self.listBox.delete(0, END)
self.words.clear()
path = os.path.expanduser('~/Desktop')
vocabulary = os.path.join(path, 'Vocabulary', 'Words.xml')
if not os.path.exists(vocabulary):
if not os.path.exists(os.path.dirname(vocabulary)):
os.mkdir(os.path.dirname(vocabulary))
doc = ET.Element('Words')
tree = ET.ElementTree(doc)
tree.write(vocabulary)
else:
tree = ET.ElementTree(file=vocabulary)
for node in tree.findall('WordOrPhrase'):
w = Word(node.find('Word').text, node.find('Explanation').text, node.find('Translation').text,
node.find('Examples').text)
self.words.append(w)
self.listBox.insert(END, w.wordorphrase)
def save_all(self):
path = os.path.expanduser('~/Desktop')
vocabulary = os.path.join(path, 'Vocabulary', 'Words.xml')
tree = ET.ElementTree(file=vocabulary)
for xNode in tree.getroot().findall('WordOrPhrase'):
tree.getroot().remove(xNode)
for w in self.words:
xTop = ET.Element('WordOrPhrase')
xWord = ET.Element('Word')
xExplanation = ET.Element('Explanation')
xTranslation = ET.Element('Translation')
xExamples = ET.Element('Examples')
xWord.text = w.wordorphrase
xExplanation.text = w.explanation
xTranslation.text = w.translation
xExamples.text = w.example
xTop.append(xWord)
xTop.append(xExplanation)
xTop.append(xTranslation)
xTop.append(xExamples)
tree.getroot().append(xTop)
tree.write(vocabulary)
def add_item(self):
if len(self.listBox.curselection()) > 0:
messagebox.showinfo('Notification', 'Please make sure you have no words selected!')
elif self.txt_WordOrPhrase['state'] == 'disabled':
messagebox.showinfo('Notification', 'Please make sure you refresh fields first!')
else:
if len(self.txt_WordOrPhrase.get("1.0", "end-1c")) == 0:
messagebox.showinfo('Notification', 'Please enter the word!')
else:
w = Word(self.get_word(), self.get_explanation(), self.get_translation(), self.get_example())
if not any(x for x in self.words if x.wordorphrase == w.wordorphrase):
self.words.append(w)
self.listBox.insert(END, w.wordorphrase)
else:
messagebox.showinfo('Notification', 'That word already exists in your vocabulary!')
self.clear_all()
self.sync()
self.word_count()
self.save_all()
def remove_item(self):
for index in reversed(self.listBox.curselection()):
self.listBox.delete(index)
del self.words[index]
def edit_item(self):
if len(self.listBox.curselection()) > 0:
self.read_only_OFF()
else:
messagebox.showinfo('Notification', 'Nothing is selected!')
self.btn_Edit.config(state = 'disabled')
self.read_only_ON()
self.sync()
def save_item(self):
if len(self.listBox.curselection()) > 0:
word = self.find_word(self.listBox.curselection())
word.wordorphrase = self.get_word()
word.explanation = self.get_explanation()
word.translation = self.get_translation()
word.example = self.get_example()
#self.listBox.curselection() = self.get_word()
self.read_only_ON()
else:
messagebox.showinfo('Notification', 'You have not selected any word!')
self.save_all()
self.word_count()
def sync(self):
pass
def word_count(self):
pass
def clear_all(self):
self.txt_WordOrPhrase.delete('1.0', END)
self.txt_Explanation.delete('1.0', END)
self.txt_Translation.delete('1.0', END)
self.txt_Example.delete('1.0', END)
def refresh_all(self):
self.clear_all()
self.read_only_OFF()
self.btn_Edit.config(state = 'disabled')
self.word_count()
self.sync()
def get_word(self):
return self.txt_WordOrPhrase.get('1.0', '1.0 lineend')
def get_explanation(self):
return self.txt_Explanation.get('1.0', '1.0 lineend')
def get_translation(self):
return self.txt_Translation.get('1.0', '1.0 lineend')
def get_example(self):
return self.txt_Example.get('1.0', '1.0 lineend')
def find_word(self, word):
for x in self.words:
if x.wordorphrase == word:
return x
def selectedIndexChanged(self, event = None):
self.read_only_OFF()
selected = self.listBox.curselection()
if len(selected) == 0:
self.btn_Edit.config(state = 'disabled')
self.refresh_all()
return
try:
word = self.words[selected[0]]
self.clear_all()
self.txt_WordOrPhrase.insert(END, word.wordorphrase)
self.txt_Explanation.insert(END, word.explanation)
self.txt_Translation.insert(END, word.translation)
self.txt_Example.insert(END, word.example)
self.read_only_ON()
self.btn_Edit.config(state = 'normal')
except Exception:
return
def read_only_ON(self):
self.txt_WordOrPhrase.config(state = 'disabled')
self.txt_Explanation.config(state = 'disabled')
self.txt_Translation.config(state = 'disabled')
self.txt_Example.config(state = 'disabled')
def read_only_OFF(self):
self.txt_WordOrPhrase.config(state = 'normal')
self.txt_Explanation.config(state = 'normal')
self.txt_Translation.config(state = 'normal')
self.txt_Example.config(state = 'normal')
def main():
root = Tk()
gui = Vocabulary(root)
root.protocol('WM_DELETE_WINDOW', gui.on_closing)
root.mainloop()
if __name__ == '__main__':
main()
#词汇表.py
#管理未知单词的GUI程序
从tkinter进口*
从tkinter导入ttk
从tkinter导入消息框
将xml.etree.ElementTree作为ET导入
导入操作系统
类词:
def uuu init uuuu(self,wordorphrase=None,explainion=None,translation=None,example=None):
self.wordorphrase=wordorphrase
自我解释
self.example=示例
self.translation=翻译
课堂词汇(框架):
定义初始(自我,主):
帧。\uuuu初始化(自,主)
self.master=master
self.master.reshable(宽度=False,高度=False)
self.master.title(“词汇表”)
self.create_widgets()
self.words=[]
self.load_words()
def on_关闭(自):
self.save_all()
如果messagebox.askokcancel(“退出”,“您想退出吗?”):
self.master.destroy()
def创建_小部件(自):
self.buttons\u frame=frame(self.master)
self.buttons\u frame.grid(行=10,粘滞=W)
self.search\u frame=frame(self.master)
self.search\u frame.grid(行=1,粘滞=W,列span=2)
self.comboBox=ttk.comboBox(self.search\u框架,
宽度=3)
self.comboBox.grid(行=0,列=14,粘性=W)
self.comboBox['values']=('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z')
self.btn_Add=按钮(self.buttons_框架,
text='Add',
command=self.add_项)
self.btn_Add.grid(行=0,粘性=W)
self.btn_Remove=按钮(self.buttons_框架,
text='Remove',
命令=self.remove_项)
self.btn_Remove.grid(行=0,列=1,粘性=W)
self.btn_Edit=按钮(self.buttons_框架,
text='编辑',
command=self.edit\u项目)
self.btn_Edit.grid(行=0,列=2,粘性=W)
self.btn_Save=按钮(self.buttons_帧,
text='保存',
command=self.save\u项目)
self.btn_Save.grid(行=0,列=3,粘性=W)
self.btn\u刷新=按钮(self.buttons\u帧,
text='刷新',
命令=self.refresh\u all)
self.btn_Refresh.grid(行=0,列=4,粘性=W)
self.lblSearch=标签(self.search_框架,文本='search:')
self.lblSearch.grid(行=0,列=5,粘性=W)
self.txt_Search=文本(self.Search_框架,
高度=1,
宽度=70)
self.txt_Search.grid(行=0,列=6,列span=3,粘性=W)
self.lblwordorphrases=Label(self.master,text='WORDS/PHRASES:')
self.lblwordorphrases.grid(行=2,列=0)
self.lblwordphrase=标签(self.master,text='单词或短语:')
self.lblwordphrase.grid(行=2,列=1,粘性=W)
self.listBox=listBox(self.master,
选择mode='extended',
高度=34,
宽度=38)
self.listBox.grid(行=3,列=0,行跨度=7,粘性=W)
self.listBox.bind(“”,self.selectedIndexChanged)
self.txt_WordOrPhrase=文本(self.master,
高度=1,
宽度=40)
self.txt\u WordOrPhrase.grid(行=3,列=1,粘性=N)
self.lblExplanation=标签(self.master,text='解释:')
self.lblExplanation.grid(行=4,列=1,粘性=W)
self.txt_解释=文本(self.master,
高度=10,
宽度=40)
self.txt_explaution.grid(行=5,列=1,粘性=N)
self.lbltransation=Label(self.master,text='Translation:')
self.lbltransation.grid(行=6,列=1,粘性=W)
self.txt_Translation=文本(self.master,
高度=10,
宽度=40)
self.txt_Translation.grid(行=7,列=1,粘性=N)
self.lblExamples=标签(self.master,text='示例:')
self.lblExamples.grid(行=8,列=1,粘性=W)
self.txt_示例=文本(self.master,
高度=10,
宽度=40)
self.txt_Example.grid(行=9,列=1,粘性=S)
def load_字(自身):
self.listBox.delete(0,结束)
self.words.clear()
path=os.path.expanduser(“~/Desktop”)
词汇=os.path.join(路径“词汇”,“Words.xml”)
如果不存在os.path(词汇表):
如果不存在os.path.exists(os.path.dirname(词汇)):
os.mkdir(os.path.dirname(词汇表))
doc=ET.Element('Words')
tree=ET.ElementTree(文档)
树。写(词汇)
其他:
# Vocabulary.py
# GUI program to manage unknown words
from tkinter import *
from tkinter import ttk
from tkinter import messagebox
import xml.etree.ElementTree as ET
import os
class Word:
def __init__(self, wordorphrase = None, explanation = None, translation = None, example = None):
self.wordorphrase = wordorphrase
self.explanation = explanation
self.example = example
self.translation = translation
class Vocabulary(Frame):
def __init__(self, master):
Frame.__init__(self, master)
self.master = master
self.master.resizable(width = False, height = False)
self.master.title('Vocabulary')
self.create_widgets()
self.words = []
self.load_words()
def on_closing(self):
self.save_all()
if messagebox.askokcancel("Quit", "Do you want to quit?"):
self.master.destroy()
def create_widgets(self):
self.buttons_frame = Frame(self.master)
self.buttons_frame.grid(row = 10, sticky = W)
self.search_frame = Frame(self.master)
self.search_frame.grid(row = 1, sticky = W, columnspan = 2)
self.comboBox = ttk.Combobox(self.search_frame,
width = 3)
self.comboBox.grid(row = 0, column = 14, sticky = W)
self.comboBox['values'] = ( 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' )
self.btn_Add = Button(self.buttons_frame,
text = 'Add',
command = self.add_item)
self.btn_Add.grid(row = 0, sticky = W)
self.btn_Remove = Button(self.buttons_frame,
text = 'Remove',
command = self.remove_item)
self.btn_Remove.grid(row = 0, column = 1, sticky = W)
self.btn_Edit = Button(self.buttons_frame,
text = 'Edit',
command = self.edit_item)
self.btn_Edit.grid(row = 0, column = 2, sticky = W)
self.btn_Save = Button(self.buttons_frame,
text = 'Save',
command = self.save_item)
self.btn_Save.grid(row = 0, column = 3, sticky = W)
self.btn_Refresh = Button(self.buttons_frame,
text = 'Refresh',
command = self.refresh_all)
self.btn_Refresh.grid(row = 0, column = 4, sticky = W)
self.lblSearch = Label(self.search_frame, text = 'SEARCH: ')
self.lblSearch.grid(row = 0, column = 5, sticky = W)
self.txt_Search = Text(self.search_frame,
height = 1,
width = 70)
self.txt_Search.grid(row = 0, column = 6, columnspan = 3, sticky = W)
self.lblWordsOrPhrases = Label(self.master, text = 'WORDS/PHRASES:')
self.lblWordsOrPhrases.grid(row = 2, column = 0)
self.lblWordOrPhrase = Label(self.master, text = 'Word or phrase:')
self.lblWordOrPhrase.grid(row = 2, column = 1, sticky = W)
self.listBox = Listbox(self.master,
selectmode='extended',
height = 34,
width = 38)
self.listBox.grid(row = 3, column = 0, rowspan = 7, sticky = W)
self.listBox.bind('<<ListboxSelect>>', self.selectedIndexChanged)
self.txt_WordOrPhrase = Text(self.master,
height = 1,
width = 40)
self.txt_WordOrPhrase.grid(row = 3, column = 1, sticky = N)
self.lblExplanation = Label(self.master, text = 'Explanation:')
self.lblExplanation.grid(row = 4, column = 1, sticky = W)
self.txt_Explanation = Text(self.master,
height = 10,
width = 40)
self.txt_Explanation.grid(row = 5, column = 1, sticky = N)
self.lblTranslation = Label(self.master, text = 'Translation:')
self.lblTranslation.grid(row = 6, column = 1, sticky = W)
self.txt_Translation = Text(self.master,
height = 10,
width = 40)
self.txt_Translation.grid(row = 7, column = 1, sticky = N)
self.lblExamples = Label(self.master, text = 'Example(s):')
self.lblExamples.grid(row = 8, column = 1, sticky = W)
self.txt_Example = Text(self.master,
height = 10,
width = 40)
self.txt_Example.grid(row = 9, column = 1, sticky = S)
def load_words(self):
self.listBox.delete(0, END)
self.words.clear()
path = os.path.expanduser('~/Desktop')
vocabulary = os.path.join(path, 'Vocabulary', 'Words.xml')
if not os.path.exists(vocabulary):
if not os.path.exists(os.path.dirname(vocabulary)):
os.mkdir(os.path.dirname(vocabulary))
doc = ET.Element('Words')
tree = ET.ElementTree(doc)
tree.write(vocabulary)
else:
tree = ET.ElementTree(file=vocabulary)
for node in tree.findall('WordOrPhrase'):
w = Word(node.find('Word').text, node.find('Explanation').text, node.find('Translation').text,
node.find('Examples').text)
self.words.append(w)
self.listBox.insert(END, w.wordorphrase)
def save_all(self):
path = os.path.expanduser('~/Desktop')
vocabulary = os.path.join(path, 'Vocabulary', 'Words.xml')
tree = ET.ElementTree(file=vocabulary)
for xNode in tree.getroot().findall('WordOrPhrase'):
tree.getroot().remove(xNode)
for w in self.words:
xTop = ET.Element('WordOrPhrase')
xWord = ET.Element('Word')
xExplanation = ET.Element('Explanation')
xTranslation = ET.Element('Translation')
xExamples = ET.Element('Examples')
xWord.text = w.wordorphrase
xExplanation.text = w.explanation
xTranslation.text = w.translation
xExamples.text = w.example
xTop.append(xWord)
xTop.append(xExplanation)
xTop.append(xTranslation)
xTop.append(xExamples)
tree.getroot().append(xTop)
tree.write(vocabulary)
def add_item(self):
if len(self.listBox.curselection()) > 0:
messagebox.showinfo('Notification', 'Please make sure you have no words selected!')
elif self.txt_WordOrPhrase['state'] == 'disabled':
messagebox.showinfo('Notification', 'Please make sure you refresh fields first!')
else:
if len(self.txt_WordOrPhrase.get("1.0", "end-1c")) == 0:
messagebox.showinfo('Notification', 'Please enter the word!')
else:
w = Word(self.get_word(), self.get_explanation(), self.get_translation(), self.get_example())
if not any(x for x in self.words if x.wordorphrase == w.wordorphrase):
self.words.append(w)
self.listBox.insert(END, w.wordorphrase)
else:
messagebox.showinfo('Notification', 'That word already exists in your vocabulary!')
self.clear_all()
self.sync()
self.word_count()
self.save_all()
def remove_item(self):
for index in reversed(self.listBox.curselection()):
self.listBox.delete(index)
del self.words[index]
def edit_item(self):
if len(self.listBox.curselection()) > 0:
self.read_only_OFF()
else:
messagebox.showinfo('Notification', 'Nothing is selected!')
self.btn_Edit.config(state = 'disabled')
self.read_only_ON()
self.sync()
def save_item(self):
if len(self.listBox.curselection()) > 0:
word = self.find_word(self.listBox.curselection())
word.wordorphrase = self.get_word()
word.explanation = self.get_explanation()
word.translation = self.get_translation()
word.example = self.get_example()
#self.listBox.curselection() = self.get_word()
self.read_only_ON()
else:
messagebox.showinfo('Notification', 'You have not selected any word!')
self.save_all()
self.word_count()
def sync(self):
pass
def word_count(self):
pass
def clear_all(self):
self.txt_WordOrPhrase.delete('1.0', END)
self.txt_Explanation.delete('1.0', END)
self.txt_Translation.delete('1.0', END)
self.txt_Example.delete('1.0', END)
def refresh_all(self):
self.clear_all()
self.read_only_OFF()
self.btn_Edit.config(state = 'disabled')
self.word_count()
self.sync()
def get_word(self):
return self.txt_WordOrPhrase.get('1.0', '1.0 lineend')
def get_explanation(self):
return self.txt_Explanation.get('1.0', '1.0 lineend')
def get_translation(self):
return self.txt_Translation.get('1.0', '1.0 lineend')
def get_example(self):
return self.txt_Example.get('1.0', '1.0 lineend')
def find_word(self, word):
for x in self.words:
if x.wordorphrase == word:
return x
def selectedIndexChanged(self, event = None):
self.read_only_OFF()
selected = self.listBox.curselection()
if len(selected) == 0:
self.btn_Edit.config(state = 'disabled')
self.refresh_all()
return
try:
word = self.words[selected[0]]
self.clear_all()
self.txt_WordOrPhrase.insert(END, word.wordorphrase)
self.txt_Explanation.insert(END, word.explanation)
self.txt_Translation.insert(END, word.translation)
self.txt_Example.insert(END, word.example)
self.read_only_ON()
self.btn_Edit.config(state = 'normal')
except Exception:
return
def read_only_ON(self):
self.txt_WordOrPhrase.config(state = 'disabled')
self.txt_Explanation.config(state = 'disabled')
self.txt_Translation.config(state = 'disabled')
self.txt_Example.config(state = 'disabled')
def read_only_OFF(self):
self.txt_WordOrPhrase.config(state = 'normal')
self.txt_Explanation.config(state = 'normal')
self.txt_Translation.config(state = 'normal')
self.txt_Example.config(state = 'normal')
def main():
root = Tk()
gui = Vocabulary(root)
root.protocol('WM_DELETE_WINDOW', gui.on_closing)
root.mainloop()
if __name__ == '__main__':
main()
def save_item(self):
if len(self.listBox.curselection()) > 0:
word = self.find_word(self.listBox.get(ACTIVE))
word.wordorphrase = self.get_word()
word.explanation = self.get_explanation()
word.translation = self.get_translation()
word.example = self.get_example()
word_index = self.listBox.curselection()[0]
self.listBox.delete(word_index)
self.listBox.insert(word_index, self.get_word())
self.read_only_ON()
else:
messagebox.showinfo('Notification', 'You have not selected any word!')
self.save_all()
self.word_count()