Получение состояния виджета записи tkinter - PullRequest
0 голосов
/ 25 апреля 2018

Есть ли способ получить текущее состояние виджета записи? Я думал, что смогу с помощью метода .winfo, но это не так? Попытка создать функцию / кнопку, которая действует по-разному в зависимости от состояния виджета ввода ... Пока что не повезло ... есть идеи?

Виджеты ввода и кнопки:

    self.contact_phone = tk.Entry(contact_frame, font='arial 10 bold', relief='flat', bg='grey60', textvariable=self.var3, state='readonly', readonlybackground='grey60')
    self.contact_phone.place(anchor='nw', y=50)

    self.change_phone = tk.Button(contact_frame, text='Change', font='arial 10 bold', bd=2, bg='grey80', command=self.changephone)
    self.change_phone.place(anchor='nw', y=48, x=180)

предложенная функция (для краткости опущена информация об открытии / записи в файл):

def changephone(self):
    if #the state of the widget is readonly:
        '''config the widget to allow entry'''
        self.contact_phone.config(state='normal', relief='sunken', bg='white', bd=2)
        '''change the text on the button to reflect the other functionality'''
        self.change_phone.config(text='Apply')
    elif #the state of the widget is normal:
        '''get the new contents and write it to a file'''
        newnumber = self.contact_phone.get()
        #open a file and write the new number to it...
        '''return the widget and button to their previous states'''
        self.contact_phone.config(state='readonly', relief='sunken', readonlybackground='grey60')
        self.change_phone.config(text='Change')

Спасибо

Mike

...