Как вернуть забытый виджет, помещенный в сетку, используя grid_remove обратно в активное состояние? - PullRequest
0 голосов
/ 26 июня 2018

У меня есть следующий фрагмент кода:
a.Где у него две радиокнопки.
б.щелкнув одну из кнопок, удалите другую радиокнопку, используя grid_remove().
c.А затем он добавляет метку и виджет записи.
d.И затем я попытался сделать dictionary['element'].grid(), чтобы вернуть удаленный виджет, но я не вижу, чтобы он снова помещался обратно.

#!/usr/intel/bin/python2.7

import Tkinter
from Tkinter import *

class simpleapp_tk(Tkinter.Tk):

def __init__(self,parent):
    Tkinter.Tk.__init__(self,parent)
    self.parent = parent

    self.entries = {}
    self.sc_button = None
    self.cv_button = None
    self.scl1 = None 
    self.sce1 = None
    self.scl2 = None

    self.initialize()

def initialize(self):
    self.grid()

    initial_screen_buttons = (
     ('self.sc_button', 'Single Component','v', 1, self.singlecomponent, 4, 'W'),
     ('self.cv_button', 'Comple Component','v', 2, self.complecomponent, 5, 'W')
    )

    #entries = []
    for _ButtonName , _Text, _Variable, _Value, _Operation, _Row, _Sticky in initial_screen_buttons: 
        _ButtonName_tmp = Radiobutton(self, anchor="center", text=_Text, variable=_Variable, value=_Value, command=_Operation)
        _ButtonName_tmp.grid(row=_Row, sticky=_Sticky)
        _ButtonName_tmp.rowconfigure(_Row,weight=1)
        self.entries[_ButtonName] =_ButtonName_tmp
        print 'Name of the button is ', _ButtonName
        print 'Name of the button is ', _ButtonName_tmp

    self.grid_columnconfigure(0,weight=1)
    self.grid_columnconfigure(1,weight=1)
    self.grid_columnconfigure(2,weight=1)
    self.grid_rowconfigure(0,weight=1)
    self.grid_rowconfigure(1,weight=1)

def singlecomponent(self):
    #self.cv_button.grid_forget()
    print 'Values in entries', self.entries
    print 'Values in entries', self.entries["self.cv_button"]
    self.entries['self.cv_button'].grid_remove()
    #self.entries[1].grid_forget()

    # print "value of v is %d"%v.get()

    if not (self.scl1):
        self.scl1 = Label(self, text="Enter The Widget Name You Wanted To Create: ")
        self.scl1.grid(row=6)

    if not (self.sce1): 
        self.sce1 = Entry(self)
        self.sce1.grid(row=7)

    if not (self.scl2):
        self.scl2 = Label(self, text="Which Widget You Wanted To Create: ")
        self.scl2.grid(row=8)

    self.entries['self.cv_button'].grid() #Calling the grid back is not getting placed back again.

def complecomponent(self):
    #self.sc_button.grid_forget()
    print 'Values in entries', self.entries['self.sc_button']
    self.entries['self.sc_button'].grid_forget()
    #self.entries[0].grid_forget()


if __name__ == "__main__":
    app = simpleapp_tk(None)
    app.title("Test App")
    app.mainloop()

Запросы:
a.Не вызовет ли grid () возврат уже удаленного виджета с помощью grid_remove ()?
b.Или есть лучшее решение, чтобы вернуть виджет?

Может кто-нибудь прокомментировать / предложить, что нужно сделать?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...