I wish to print from a list where the user enters an input and then has that input printed from a list. This however doesn't work without a blank string in the list as it says that the list is too short for the data to be shown in a label. I want for this to have the input printed immediately after pressing the continue button not after pressing the next button.
from tkinter import *
class Traveller:
def __init__(self, parent):
self.names = [""]
self.E_phone = "f"
self.E_name = "q"
self.count = 0
self.go = Frame(parent, width=500, height=450, bg="snow", pady=30, padx=10)
self.go.grid(row=1, column=0)
self.go.grid_propagate(0) # to reserve space required for frame
self.dataView = Frame(parent, width=500, height=500, bg="snow", pady=30, padx=10)
name = Label(self.go, text="Name:", bg="snow")
name.grid(row=1, column=0, sticky=E)
self.E_name = Entry(self.go, width=40)
self.E_name.grid(row=1, column=1, sticky=W, pady=4)
menuButton = Button(self.go, text="Continue", command=self.dataSave)
menuButton.grid(row=2, column=1, pady=4)
dataTitle = Label(self.dataView, text="Here is all of the inputted data:", bg="snow")
dataTitle.grid(row=2, column=0)
dataExit = Button(self.dataView, text="Return", command=self.returnT)
dataExit.grid(row=1, column=0, pady=5)
nextData = Button(self.dataView, text="Next", command=self.NData)
nextData.grid(row=4, column=0, pady=5)
prevData = Button(self.dataView, text="Previous", command=self.PData)
prevData.grid(row=4, column=1, pady=5)
self.everything = Label(self.dataView, text="The person" + self.names[self.count], bg = "snow")
self.everything.grid(row=3, column = 0)
def dataSave(self):
self.names.append(self.E_name.get())
self.go.grid_remove()
self.dataView.grid(row=1, column=0)
self.dataView.grid_propagate(0)
# clearing the entry boxes
self.E_name.delete(0, END)
def returnT(self):
self.dataView.grid_remove()
self.go.grid(row=1, column=0)
self.go.grid_propagate(0)
def NData(self):
self.count = self.count + 1
self.everything.configure(text = "The person " + self.names[self.count])
def PData(self):
if self.count >= 1:
self.count = self.count - 1
self.everything.configure(text = "The person " + self.names[self.count])
# main routine
if __name__ == "__main__":
root = Tk()
root.title("Traveller Details")
play = Traveller(root)
root.geometry("500x450+0+0")
root.mainloop()
Related
I am recreating the game Wordle for practice.
I am trying to find a function that allows me to destroy all widgets in my tkinter window.
root.destroy() isn't a solution because it just closes the whole window.
I want to use this function to, whenever we win the game, restart the whole program without having to manually do it.
Program:
from tkinter import *
from tkinter import ttk
import tkinter as tk
from english_words import english_words_alpha_set
import time
guess = "bored"
guess = guess.upper()
word=""
a=0
def callback1(var, index, mode):
root.entry2.configure(state="normal")
root.entry2.focus()
root.entry1.configure(state="disabled")
root.hasfocus = "entry2"
def callback2(var, index, mode):
root.entry3.configure(state="normal")
root.entry3.focus()
root.entry2.configure(state="disabled")
root.hasfocus = "entry3"
def callback3(var, index, mode):
root.entry4.configure(state="normal")
root.entry4.focus()
root.entry3.configure(state="disabled")
root.hasfocus = "entry4"
def callback4(var, index, mode):
root.entry5.configure(state="normal")
root.entry5.focus()
root.entry4.configure(state="disabled")
root.hasfocus = "entry5"
def callback5(var, index, mode):
root.entry5.configure(state="disabled")
root.hasfocus = "none"
def newRow():
boxes = [root.box1, root.box2, root.box3, root.box4, root.box5]
word = root.name1.get() + root.name2.get() + root.name3.get() + root.name4.get() + root.name5.get()
word=word.upper()
root.greenBoxes=0
def checkBg():
if word[a] == guess[a]:
root.greenBoxes=root.greenBoxes+1
print("greenBoxes=", root.greenBoxes)
return '#538D4E'
elif word[a] in guess:
return '#B59F3B'
else:
return '#3A3A3C'
root.entry1.destroy()
root.entry2.destroy()
root.entry3.destroy()
root.entry4.destroy()
root.entry5.destroy()
a=0
while a < 5:
boxes[a].configure(text=word[a], bg=checkBg(), fg = "white")
a=a+1
if root.greenBoxes == 5: #if player won:
root.WinMsg = Label(root, height=2, width=28, bg='#2d2d2f', fg='white', text='You\'ve won! The word was \"' + guess[0] + guess[1:5].lower() +"\"", font="Calibri 20")
root.WinMsg.place(x=65, y=100) #say that he won
#*destroy all widgets*
root.CreateWindow() #remake all widgets (to start a new game)
return
root.rows = root.rows+1
if root.rows < 6: #if player still have any try
root.d=root.d+70
root.createBoxes()
root.createEntry()
else: #if player lost
root.GameOverMsg = Label(root, height=2, width=28, bg='#2d2d2f', fg='white', text='You\'ve lost! The word was \"' + guess[0] + guess[1:5].lower() +"\"", font="Calibri 20")
root.GameOverMsg.place(x=65, y=100) #says that he lost
#*destroy all widgets*
root.CreateWindow() #remake all widgets (to start a new game)
return
class root(Tk):
def __init__(self):
super(root, self).__init__()
self.title("Wordle")
self.minsize(580,465)
self.windowBG = '#121213'
self.CreateWindow()
def CreateWindow(self):
self.configure(bg=self.windowBG)
self.hasfocus = ""
self.d=0
self.rows=0
self.greenBoxes = 0
self.createBoxes()
self.createEntry()
self.backspace = Button(self, text="Backspace", width=8, font ="Calibri 18", command=self.do_backspace)
self.backspace.place(x=465, y=62)
self.enter = Button(self, text="Enter", width=6, font ="Calibri 18", command=self.do_enter)
self.enter.place(x=480, y=125)
def createBoxes(self):
self.box1 = tk.Label(self, text="", font="Calibri", height=2, width=6, bg="#3A3A3C")
self.box1.place(x=70, y=30+self.d)
self.box2 = tk.Label(self, text="", font="Calibri", height=2, width=6, bg="#3A3A3C")
self.box2.place(x=150, y=30+self.d)
self.box3 = tk.Label(self, text="", font="Calibri", height=2, width=6, bg="#3A3A3C")
self.box3.place(x=230, y=30+self.d)
self.box4 = tk.Label(self, text="", font="Calibri", height=2, width=6, bg="#3A3A3C")
self.box4.place(x=310, y=30+self.d)
self.box5 = tk.Label(self, text="", font="Calibri", height=2, width=6, bg="#3A3A3C")
self.box5.place(x=390, y=30+self.d)
def do_backspace(self):
if self.hasfocus == "entry1":
pass
elif self.hasfocus == "entry2":
self.entry1.configure(state="normal")
self.entry1.delete(0, 'end')
self.entry1.configure(state="normal")
self.entry1.focus()
self.hasfocus="entry1"
self.entry2.configure(state="disabled")
elif self.hasfocus == "entry3":
self.entry2.configure(state="normal")
self.entry2.delete(0, 'end')
self.entry2.configure(state="normal")
self.entry2.focus()
self.hasfocus="entry2"
self.entry3.configure(state="disabled")
elif self.hasfocus == "entry4":
self.entry3.configure(state="normal")
self.entry3.delete(0, 'end')
self.entry3.configure(state="normal")
self.entry3.focus()
self.hasfocus="entry3"
self.entry4.configure(state="disabled")
elif self.hasfocus == "entry5":
self.entry4.configure(state="normal")
self.entry4.delete(0, 'end')
self.entry4.configure(state="normal")
self.entry4.focus()
self.hasfocus="entry4"
self.entry5.configure(state="disabled")
else:
self.entry5.configure(state="normal")
self.entry5.delete(0, 'end')
self.entry5.configure(state="normal")
self.entry5.focus()
self.hasfocus="entry5"
def do_enter(self):
if len(self.name1.get() + self.name2.get() + self.name3.get() + self.name4.get() + self.name5.get()) == 5:
newRow()
else:
self.FiveLetterWord = Label(self, height=2, width=22, bg='#2d2d2f', fg='white', text='Word must be of 5 letters', font="Calibri 20", background=self.windowBG,highlightbackground='#3A3A3C', highlightthickness=2)
self.FiveLetterWord.place(x=100, y=100)
self.update_idletasks()
self.after(3000)
self.FiveLetterWord.destroy()
def createEntry(self):
self.name1 = StringVar()
self.entry1 = ttk.Entry(self, width=2, textvariable = self.name1, font="Calibri 15", justify='center')
self.entry1.place(x=90, y=40+self.d)
self.name2 = StringVar()
self.entry2 = ttk.Entry(self, width=2, textvariable = self.name2, font="Calibri 15", justify='center')
self.entry2.place(x=170, y=40+self.d)
self.entry2.configure(state="disabled")
self.name3 = StringVar()
self.entry3 = ttk.Entry(self, width=2, textvariable = self.name3, font="Calibri 15", justify='center')
self.entry3.place(x=250, y=40+self.d)
self.entry3.configure(state="disabled")
self.name4 = StringVar()
self.entry4 = ttk.Entry(self, width=2, textvariable = self.name4, font="Calibri 15", justify='center')
self.entry4.place(x=330, y=40+self.d)
self.entry4.configure(state="disabled")
self.name5 = StringVar()
self.entry5 = ttk.Entry(self, width=2, textvariable = self.name5, font="Calibri 15", justify='center')
self.entry5.place(x=410, y=40+self.d)
self.entry5.configure(state="disabled")
self.entry1.focus() ; hasfocus = "entry1"
self.name1.trace_add("write", callback1)
self.name2.trace_add("write", callback2)
self.name3.trace_add("write", callback3)
self.name4.trace_add("write", callback4)
self.name5.trace_add("write", callback5)
root=root()
root.mainloop()
You can use winfo_children to get a list of all child widgets of the root window, and then you can iterate over the list to destroy each child.
for child in root.winfo_children():
child.destroy()
From that point on, you have a root window with nothing in it.
from tkinter import *
window = Tk()
window.geometry("600x400+400+250")
window.title('Expenses Tracker')
class ExpensesTrack:
row_list = []
list_box = []
dict1 = dict()
def __init__(self,master):
self.title1 = Label(window, padx=15, pady=8, text='Enter the item').grid(row=0, column=0)
self.title_price = Label(window, padx=8, pady=8, text='Enter the price').grid(row=1, column=0)
self.entry1 = Entry(window, font='NEWTIMESROMAN')
self.entry1.grid(row=0, column=1)
self.entry2 = Entry(window, font='NEWTIMESROMAN')
self.entry2.grid(row=1, column=1)
self.blank1 = Label(window).grid(row=3, column=1, columnspan=3)
self.title3 = Label(window, text='Name of Item').grid(row=4, column=1 )
self.title4 = Label(window, text='Price').grid(row=4, column=2)
self.button1 = Button(window, text='Add', command= self.buttonclick).grid(row=1, column=4, padx=20)
self.button2 = Button(window, text='Remove' )
self.button2.grid(row=5, column=4, padx=15)
def buttonclick(self):
var = IntVar()
def cmd():
i = var.get()
print(i)
row = len(self.row_list) + 5
name = Label(window, text=self.entry1.get())
price = Label(window, text="$" + self.entry2.get())
box = Checkbutton(window ,variable= var, command= cmd)
name.grid(row= row, column=1)
price.grid(row= row, column=2)
box.grid(row=row, column=0)
self.row_list.append(len(self.row_list) + 5)
self.list_box.append(box)
self.dict1[row] = price, name
self.entry1.delete(0, END)
self.entry2.delete(0, END)
e = ExpensesTrack(window)
window.mainloop()
''' I make a list of box when every time , I add check button. I want to use destroy function iterate from the list_box. but I don't know how to check value of var , it is 1 or 0 for respective check button and later, I would add name and price label with it. Can any one tell a way that how to get var value from the box from list_box or any other way.
e = ExpensesTrack(window)
window.mainloop()
to remove items you shoud nav by var
list_var = []
# self.button2 = Button(window, text='Remove', command=self.remove )
def remove(self):
for i, var in enumerate(self.list_var):
if var.get() == 1:
self.list_box[i].destroy()
self.dict1[i][0].destroy()
self.dict1[i][1].destroy()
def buttonclick(self):
var = IntVar()
row = len(self.row_list) + 5
name = Label(window, text=self.entry1.get())
price = Label(window, text="$" + self.entry2.get())
box = Checkbutton(window ,variable= var)
name.grid(row= row, column=1)
price.grid(row= row, column=2)
box.grid(row=row, column=0)
self.dict1[len(self.row_list)] = price, name
self.row_list.append(len(self.row_list) + 5)
self.list_box.append(box)
self.list_var.append(var)
self.entry1.delete(0, END)
self.entry2.delete(0, END)
I have 2 different python GUI menus in 2 different scripts.
A dropdown list to select
A menu where numbers can be input and output at the same GUI
I want to merge these 2 together so that both appear in the same GUI menu.
I am having trouble doing it because the structure in both python scripts is different.
Please advice.
Sharing both scripts below:
1st one
from tkinter import *
class Custombox:
def __init__(self, title, text):
self.title = title
self.text = text
def store():
self.new = self.entry.get() # storing data from entry box onto variable
if self.new == '50': # checking
a.change('ACCEPTED') # changing text
elif self.new == '40':
a.change('Increase frequency') # else, changing text
else:
a.change('Decrease frequency') # else, changing text
self.win = Toplevel()
self.win.title(self.title)
# self.win.geometry('400x150')
self.win.wm_attributes('-topmost', True)
self.label = Label(self.win, text=self.text)
self.label.grid(row=0, column=0, pady=(20, 10), columnspan=3, sticky='w', padx=10)
self.l = Label(self.win)
self.entry = Entry(self.win, width=50)
self.entry.grid(row=1, column=1, columnspan=2, padx=10)
self.b1 = Button(self.win, text='Attack', width=10, command=store)
self.b1.grid(row=3, column=1, pady=10)
# self.b2 = Button(self.win, text='Cancel', width=10, command=self.win.destroy)
# self.b2.grid(row=3, column=2, pady=10)
def __str__(self):
return str(self.new)
def change(self, ran_text):
self.l.config(text=ran_text, font=(0, 12))
self.l.grid(row=2, column=1, columnspan=3, sticky='nsew', pady=5)
root = Tk()
root.withdraw()
a = Custombox('User learning platform', 'Select the frequency of the victim sensor.')
root.mainloop()
2nd one
from tkinter import *
root = Tk()
root.title("GUI platform")
# Add a grid
mainframe = Frame(root)
mainframe.grid(column=0,row=0, sticky=(N,W,E,S) )
mainframe.columnconfigure(0, weight = 1)
mainframe.rowconfigure(0, weight = 1)
mainframe.pack(pady = 100, padx = 100)
# Create a Tkinter variable
tkvar = StringVar(root)
# Dictionary with options
choices = { 'URM37','HC-SR04','SRF05','Parallax PING'}
tkvar.set('') # set the default option
popupMenu = OptionMenu(mainframe, tkvar, *choices)
Label(mainframe, text="Please select the type of Sensor for attack").grid(row = 1, column = 1)
popupMenu.grid(row = 2, column =1)
# on change dropdown value
def change_dropdown(*args):
if tkvar.get() == 'HC-SR04':
print( "Correct" )
else:
print("WRONG")
# link function to change dropdown
tkvar.trace('w', change_dropdown)
root.mainloop()
I want to know how to get input from Tkinter and put it into a variable like a phone number or a piece of text.
from tkinter import *
def show_data():
print( 'My First and Last Name are %s %s' % (fname.get(), lname.get()) )
win = Tk()
Label( win, text='First Name' ).grid( row=0 )
Label( win, text='Last Name' ).grid( row=1 )
fname = Entry( win )
lname = Entry( win )
fname.grid( row=0, column=1 )
lname.grid( row=1, column=1 )
Button( win, text='Exit', command=win.quit ).grid( row=3, column=0, sticky=W, pady=4 )
Button( win, text='Show', command=show_data ).grid( row=3, column=1, sticky=W, pady=4 )
mainloop()
Maybe this can help you:
from tkinter import *
def get_variable_value():
valueresult.set( strlname.get() + ' ' + strfname.get() ) #assign val variable to other
print(valueresult.get()) #if you want see the result in the console
root = Tk()
strfname = StringVar()
strlname = StringVar()
valueresult = StringVar()
labelf = Label(root, text = 'First Name').pack()
fname = Entry(root, justify='left', textvariable = strfname).pack() #strlname get input
labell = Label(root, text = 'Last Name').pack()
lname = Entry(root, justify='left', textvariable = strlname).pack() #strfname get input
button = Button(root, text='Show', command=get_variable_value).pack()
res = Entry(root, justify='left', textvariable = valueresult).pack() #only to show result
root.mainloop()
You haven't provided any code but you could try:
class GetPhoneNbr(object):
def __init__(self):
self.root = Tk.Tk()
self.label = Tk.Label(self.root, text="Enter phone number")
self.label.pack()
self.phoneNbr = Tk.StringVar() # <- here's what you need
Tk.Entry(self.root, textvariable=self.phoneNbr).pack()
NOTE: This is a stub of code, not the entire class definition.
Below is a minimal GUI that puts what's written in an entry to a variable, which is the button's text:
import tkinter as tk
def replace_btn_text():
b['text'] = e.get()
root = tk.Tk()
e = tk.Entry(root)
b = tk.Button(root, text="Replace me!", command=replace_btn_text)
e.pack()
b.pack()
root.mainloop()
Same example but with an OOP structure:
import tkinter as tk
class App(tk.Tk):
def __init__(self):
super().__init__()
self._create_widgets()
self._display_widgets()
def replace_btn_text(self):
""" Replaces button's text with what's written in the entry.
"""
# self._e.get() returns what's written in the
self._b['text'] = self._e.get() # entry as a string, can be assigned to a var.
def _create_widgets(self):
self._e = tk.Entry(self)
self._b = tk.Button(self, text="Replace me!", command=self.replace_btn_text)
def _display_widgets(self):
self._e.pack()
self._b.pack()
if __name__ == '__main__':
root = App()
root.mainloop()
I have looked at several online tutorials, none of them seem to work properly, I need to have the radio button deselected once the clear button is clicked. The .deselect() method does nothing. Clearing the text and entry boxes is working properly. Please assist.
Thank you,
from tkinter import *
class Example(Frame):
def __init__(self, parent):
Frame.__init__(self, parent, background="white")
self.parent = parent
self.parent.title("TCPDUMP Creator")
#self.centerWindow()
self.pack(fill=BOTH, expand=1)
menubar = Menu(self.parent)
self.parent.config(menu=menubar)
fileMenu = Menu(menubar)
fileMenu.add_command(label="Exit", command=self.quit)
menubar.add_cascade(label="File", menu=fileMenu)
self.columnconfigure(2, weight=5)
lf = LabelFrame(parent, text="Filter Data")
lf.pack(fill="both", expand="yes")
f = LabelFrame(lf, width=600, height=300)
frame1 = LabelFrame(lf, text="Interface")
frame1.pack(side="top", fill="both")
#frame1.place(relx=0.10, rely=0.125, anchor=NW)
int_lbl = Label(frame1, text="Int.")
int_lbl.pack(side="left", fill=X)
self.int_entry = Entry(frame1, width=15)
self.int_entry.pack(side="left")
frame2 = Label(lf, text="")
frame2.pack(side='top', fill=X)
self.anyInt = BooleanVar()
Checkbutton(frame1, text="Any", variable = self.anyInt).pack(side="left")
frame2=LabelFrame(lf, text="IP Options")
frame2.pack(side="top", fill="both")
self.notSrc = BooleanVar()
Checkbutton(frame2, text = "Not--", variable = self.notSrc).pack(side="left")
self.srcIP = BooleanVar()
Checkbutton(frame2, text="Src", variable = self.srcIP).pack(side="left")
self.src_entry = Entry(frame2, width=15)
self.src_entry.pack(side="left")
self.AndOr = StringVar()
self.AndOr.set(None)
andbtn = Radiobutton(frame2, text = "And", variable = self.AndOr, value = "And").pack(side="left", padx=25)
orbtn = Radiobutton(frame2, text = "Or", variable = self.AndOr, value = "Or").pack(side="left", padx=15)
self.notDst = BooleanVar()
Checkbutton(frame2, text = "Not--", variable = self.notDst).pack(side="left", padx=20)
self.dstIP = BooleanVar()
Checkbutton(frame2, text="Dst", variable = self.dstIP).pack(side="left")
self.dst_entry = Entry(frame2, width=15)
self.dst_entry.pack(side="left")
frame3 = Label(lf, text="")
frame3.pack(side='top', fill=X)
frame3 = LabelFrame(lf, text="")
frame3.pack(side="top", fill="both")
self.AndOrport = StringVar()
self.AndOrport.set(None)
srcAnd=Radiobutton(frame3, text = "And", variable = self.AndOrport, value = "And").pack(side='left')
self.srcOr=Radiobutton(frame3, text = "Or", variable = self.AndOrport, value = "Or").pack(side='left')
frame4 = Label(lf, text="")
frame4.pack(side='top', fill=X)
frame4 = LabelFrame(lf, text="Ports")
frame4.pack(side="top", fill="both")
self.notSrcPort = BooleanVar()
Checkbutton(frame4, text = "Not--", variable = self.notSrcPort).pack(side="left")
self.srcport_lbl = Label(frame4, text="Src Port")
self.srcport_lbl.pack(side="left")
self.srcport_entry = Entry(frame4, width=15)
self.srcport_entry.pack(side="left")
self.SrcDstport = StringVar()
self.SrcDstport.set(None)
Radiobutton(frame4, text = "And", variable = self.SrcDstport, value = "And").pack(side='left', padx=25)
Radiobutton(frame4, text = "Or", variable = self.SrcDstport, value = "Or").pack(side='left', padx=15)
self.notDstPort = BooleanVar()
Checkbutton(frame4, text = "Not--", variable = self.notDstPort).pack(side="left")
self.dstport_lbl = Label(frame4, text="Dst Port")
self.dstport_lbl.pack(side="left")
self.dstport_entry = Entry(frame4, width=15)
self.dstport_entry.pack(side="left")
frame5 = Label(lf, text="")
frame5.pack(side="top", fill=X)
frame5 = LabelFrame(lf, text="Options")
frame5.pack(side="top", fill="both")
self.listInterfaces = BooleanVar()
Checkbutton(frame5, text = "List Interfaces", variable = self.listInterfaces).pack(side="left")
cap_lbl = Label(frame5, text="# of Packets to Capture")
cap_lbl.pack(side="left")
self.cap_entry = Entry(frame5, width=3)
self.cap_entry.pack(side="left")
self.noDNS = BooleanVar()
Checkbutton(frame5, text = "Don't Translate Hostnames & Ports", variable = self.noDNS).pack(side="left", padx=15)
verbosity_lbl = Label(frame5, text="Verbosity:")
verbosity_lbl.pack(side="left")
self.verbosity = StringVar()
self.verbosity.set(None)
Radiobutton(frame5, text = "Low", variable = self.verbosity, value = "-v").pack(side='left')
Radiobutton(frame5, text = "Med", variable = self.verbosity, value = "-vv").pack(side='left', padx=15)
Radiobutton(frame5, text = "High", variable = self.verbosity, value = "-vvv").pack(side='left', padx=15)
frame6 = LabelFrame(lf, text="")
frame6.pack(side="top", fill="both")
self.timeformat = StringVar()
self.timeformat.set(None)
Radiobutton(frame6, text="Human Readable Time Format", variable=self.timeformat, value="-tttt").pack(side="left", padx=10)
self.write2file = StringVar()
self.write2file.set(None)
Radiobutton(frame6, text = "Write to File", variable = self.write2file, value="-w").pack(side='left')
write_lbl = Label(frame6, text="Filename")
write_lbl.pack(side="left")
self.file_entry = Entry(frame6, width=15)
self.file_entry.pack(side='left')
frame7 = Label(lf, text="")
frame7.pack(side='top', fill=X)
frame8 = Label(lf, text="")
frame8.pack(side="top", fill=X)
createBttn = Button(frame8, text="Create", width=15, height=2, relief="ridge", anchor=CENTER, command=self.create)
createBttn.pack(side="left", padx=70)
clearBttn = Button(frame8, text="Clear", width=15, height=2, relief="ridge", anchor=CENTER, command=self.clear)
clearBttn.pack(side="left", padx=70)
self.exitBttn = Button(frame8, text="Exit", width=15, height=2, relief="ridge", anchor=CENTER, command=self.exit)
self.exitBttn.pack(side="left", padx=70)
frame9 = Label(lf, text="Filter Data")
frame9.pack(side="top", fill=X)
frame10 = Label(lf, text="")
frame10.pack(side="left")
self.filterData = Text(frame10, width=95, height=1.2)
self.filterData.pack(side="left")
def centerWindow(self):
w = 600
h = 300
sw = self.parent.winfo_screenwidth()
sh = self.parent.winfo_screenheight()
x = (sw - w)/2
y = (sh - h)/2.7
self.parent.geometry("%dx%d+%d+%d" % (w, h, x, y))
def clear(self):
try:
self.filterData.delete(0.0, END) #delete from text box
self.int_entry.delete(0, END) #delete from entry box
self.src_entry.delete(0, END)
self.dst_entry.delete(0, END)
self.srcport_entry.delete(0, END)
self.dstport_entry.delete(0, END)
self.file_entry.delete(0, END)
self.cap_entry.delete(0, END)
self.anyInt.set(0)
self.notSrc.set(0)
self.srcIP.set(0)
self.noDNS.set(0)
self.listInterfaces.set(0)
self.notDstPort.set(0)
self.notSrcPort.set(0)
self.dstIP.set(0)
self.srcAnd.deselect()
self.srcOr.deselect()
self.SrcDstport.deselect()
deselect(self.timeformat)
self.write2file.deselect()
self.SrcDstport.deselect()
except:
pass
def exit(self):
self.quit()
def create(self):
if self.anyInt.get():
self.filterData.insert(0.0, "tcpdump " + "-i " + "any")
else:
self.filterData.insert(0.0, "tcpdump " + "-i " + self.int_entry.get())
def main():
root = Tk()
app = Example(root)
root.mainloop()
if __name__ == '__main__':
main()
self.SrcDstport.deselect()
You are trying to deselect the StringVar. You need to set it to something that isn't an option, in other words a value that none of the Radiobuttons use in the value argument:
self.SrcDstport.set(None)