Sumit
Sumit

Reputation: 2023

Problem in clearing frame using tkinter python

I am new to tkinter Python module and creating a very simple UI with tkinter. Its basically a optical card which will first ask for card number. User can enter "Card1 or Card2". For Card1 there is one more edit which ask for KM range like 10KM, 40KM, 80KM and user can enter the value specified and it gives the optimal value and acceptable value.

Code is working fine. Only problem is with clearing the information using clear button for Card1. I am not able to clear the complete information for Card1 which includes clearing the edit box and outout.

Below is the code

from tkinter import *
from tkinter import ttk
import tkinter

frm = Tk()
frm.geometry('600x400')
frm.title("Optical Power Specs")
bg = "#94FB9E"
fnt = 'tahoma 15 bold'
frm.config(bg=bg)
frm.resizable(False, False)
#frm.iconbitmap('f.gif')
frame = Frame(frm, bg=bg)
frame2 = Frame(frm, bg=bg)

frame4 = Frame(frm, bg=bg)



def f():
    global lbl104080
    global frame3
    global txt104080
    if str(txt1.get()) == 'Card1':
        print("entered ehre")
        frame3 = Frame(frm, bg=bg)
        frame3.grid(row=3, column=0)
        txt104080 = Entry(frame3, textvariable=sv104080)
        lbl104080 = Label(frame3, text="Enter 10KM or 40KM or 80KM ", font='None 10', background=bg, padx=0)
        lbl104080.grid(row=1, column=0, pady=30)
        txt104080.grid(row=1, column=1)
        if str(txt104080.get()) == '10KM':
            lblr['text'] = (""" 
                    Optimal Value   =  -10  To -10 dBm

                    Acceptable Value =  -10 To -10 dBm

                    """)
        elif str(txt104080.get()) == '40KM':
            lblr['text'] = (""" 
                Optimal Value   =  -40 To -40 dBm

                Acceptable Value =  -40 To 40 dBm
                """)

    elif str(txt1.get()) == 'Card2':
        lblr['text'] = (""" 
        Optimal Value   =  -2 To -2 dBm

        Acceptable Value =  -2 To -2 dBm
        """)
    elif str(txt1.get()) == 'A1236':
        lblr['text'] = (""" 
        Optimal Value   =  -100 To -20 dBm

        Acceptable Value =  -3 To 1 dBm
        """)


def clea():
    # global lbl104080
    #lbl104080['text'] = ('')
    txt104080['text'] = ('')
    lbl104080.destroy()
    frame3.grid_forget()
    frame3.destroy()
    #frame3.destroy()
    lblr['text'] = ('')



sv104080 = StringVar()

opt = ttk.Label(frm, text='Optical Power Specs', font=fnt, background=bg)
Ent = ttk.Label(frame, text='Enter BOM Code OR Card Name', font='None 10', background=bg)

btnok = ttk.Button(frame2, text='OK', command=f)
btncancel = ttk.Button(frame2, text='Clear', command=clea)
lblr = ttk.Label(frame4, font='None 10', background=bg)
svname_bom = StringVar()
txt1 = Entry(frame, textvariable=svname_bom)

opt.grid(row=0, column=0, pady=5, padx=200)
frame.grid(row=1, column=0)
Ent.grid(row=0, column=0, padx=10, pady=20)
txt1.grid(row=0, column=1)
frame2.grid(row=2, column=0)

btnok.grid(row=0, column=0, padx=10, pady=20)
btncancel.grid(row=0, column=1, pady=20)
frame4.grid(row=4, column=0)
lblr.grid(row=2, column=0, pady=50, padx=100)

frm.mainloop()

Please help me to solve this issue

Upvotes: 0

Views: 54

Answers (1)

Just for fun
Just for fun

Reputation: 4225

You probably want txt1.delete(0, 'end') that will delete all text from main entry text

def clea():
    #lbl104080['text'] = ('')
    txt104080['text'] = ('')
    txt1.delete(0, 'end')
    lbl104080.destroy()
    frame3.grid_forget()
    frame3.destroy()
    #frame3.destroy()
    lblr['text'] = ('')

Upvotes: 1

Related Questions