How to deselect a radio button tkinter - python

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)

Related

tkinter root.destroy() without killing the whole window

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.

Need some insight on how to create a delete function to remove a entry. I am intermediate at python programming. stuck here for a week

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)

How to use Tkinter input into a variable in python

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()

Run more loops at the same time? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
First of all, I have to say that I'm a beginner in Python. These are my first steps in creating a class. And now my question.On that picture, I presented what my code should work.
Start the program (Run)
Check what instruments should be power on. There are three
possibilities and you can power one, two or all three Units at the
same time. (Power #A/B/C)
Furthermore, with each power unit additional you can turn on
Temperatur sensor (Temp. #A,B,C)
Depending on which units are involved to run a Loop #A, #B, #C or
for example two units #B,#C or perhaps all three.This is actually my Problem and question. How can be able to simultaneously also at
the same time, run two or maybe even three loops ?
I hope you can give me some advice and help in solving my problem.
Below I will put my code so you can refer and pay Attention what I could change or improve in my code.
import Tkinter
import visa, time, datetime
from ttk import *
from tkFileDialog import *
import tkMessageBox, os
import numpy as np
rm = visa.ResourceManager()
inst = rm.list_resources()
class Interface:
def __init__(self, parent):
self.parent = parent
parent.title("Cycling")
local_directory = os.path.dirname(os.path.realpath(__file__))
self.dataname = "/does/not/exist"
# Frame
self.frame_instruments = Tkinter.Frame(parent, bg='', colormap='new')
self.frame_settings = Tkinter.Frame(parent, bg='', colormap='new')
self.frame_image = Tkinter.Frame(parent, bg='', colormap='new')
# Labelframe
self.lframe_instrumet_a = Tkinter.LabelFrame(self.frame_instruments, text="Choose an Instruments - #A", padx=8, pady=9)
self.lframe_settings_a = Tkinter.LabelFrame(self.frame_instruments, text="Settings - #A", padx=7, pady=11)
self.lframe_instrumet_b = Tkinter.LabelFrame(self.frame_instruments, text="Choose an Instruments - #B", padx=8, pady=9)
self.lframe_settings_b = Tkinter.LabelFrame(self.frame_instruments, text="Settings - #B", padx=7, pady=11)
self.lframe_instrumet_c = Tkinter.LabelFrame(self.frame_instruments, text="Choose an Instruments - #C", padx=8, pady=9)
self.lframe_settings_c = Tkinter.LabelFrame(self.frame_instruments, text="Settings - #C", padx=7, pady=11)
# Combobox
#A
self.choices_power_supply_a_var = Tkinter.StringVar()
self.choices_power_supply_a_var.set(inst[0])
self.combo_power_supply_a = Combobox(self.lframe_instrumet_a, values=inst, textvariable=self.choices_power_supply_a_var)
self.choices_multimeter_a_var = Tkinter.StringVar()
self.choices_multimeter_a_var.set(inst[0])
self.combo_multimeter_a = Combobox(self.lframe_instrumet_a, values=inst, textvariable=self.choices_multimeter_a_var)
#B
self.choices_power_supply_b_var = Tkinter.StringVar()
self.choices_power_supply_b_var.set(inst[0])
self.combo_power_supply_b = Combobox(self.lframe_instrumet_b, values=inst, textvariable=self.choices_power_supply_b_var)
self.choices_multimeter_b_var = Tkinter.StringVar()
self.choices_multimeter_b_var.set(inst[0])
self.combo_multimeter_b = Combobox(self.lframe_instrumet_b, values=inst, textvariable=self.choices_multimeter_b_var)
#C
self.choices_power_supply_c_var = Tkinter.StringVar()
self.choices_power_supply_c_var.set(inst[0])
self.combo_power_supply_c = Combobox(self.lframe_instrumet_c, values=inst, textvariable=self.choices_power_supply_c_var)
self.choices_multimeter_c_var = Tkinter.StringVar()
self.choices_multimeter_c_var.set(inst[0])
self.combo_multimeter_c = Combobox(self.lframe_instrumet_c, values=inst, textvariable=self.choices_multimeter_c_var)
# Menu
menu = Tkinter.Menu(parent, tearoff=0)
parent.config(menu=menu)
filemenu = Tkinter.Menu(parent, tearoff=0)
menu.add_cascade(label='File', menu=filemenu)
filemenu.add_command(label='Create New File...', command=lambda: self.save_file())
helpmenu = Tkinter.Menu(menu, tearoff=0)
menu.add_cascade(label='?', menu=helpmenu)
helpmenu.add_command(label='About', command=lambda: self.about())
# Label
#A
self.label_power_supply_a = Tkinter.Label(self.lframe_instrumet_a, text="Power Supply 2200: ")
self.label_multimeter_a = Tkinter.Label(self.lframe_instrumet_a, text="Multimeter 2700: ")
self.label_voltage_range_a = Tkinter.Label(self.lframe_settings_a, text='Voltage Range [V]')
self.label_over_voltage_a = Tkinter.Label(self.lframe_settings_a, text='Over Voltage Protection [V]')
self.label_voltage_set_a = Tkinter.Label(self.lframe_settings_a, text='Set Voltage [V]')
self.label_heat_set_a = Tkinter.Label(self.lframe_settings_a, text='Heat.Set [A]')
self.label_meas_set_a = Tkinter.Label(self.lframe_settings_a, text='Meas. Set [A]')
self.label_set_time_a = Tkinter.Label(self.lframe_settings_a, text='Time Limit [s]')
self.label_set_delay_a = Tkinter.Label(self.lframe_settings_a, text='Measurement Delay [s]')
self.label_set_repeat_a = Tkinter.Label(self.lframe_settings_a, text='Repeat')
#B
self.label_power_supply_b = Tkinter.Label(self.lframe_instrumet_b, text="Power Supply 2200: ")
self.label_multimeter_b = Tkinter.Label(self.lframe_instrumet_b, text="Multimeter 2700: ")
self.label_voltage_range_b = Tkinter.Label(self.lframe_settings_b, text='Voltage Range [V]')
self.label_over_voltage_b = Tkinter.Label(self.lframe_settings_b, text='Over Voltage Protection [V]')
self.label_voltage_set_b = Tkinter.Label(self.lframe_settings_b, text='Set Voltage [V]')
self.label_heat_set_b = Tkinter.Label(self.lframe_settings_b, text='Heat.Set [A]')
self.label_meas_set_b = Tkinter.Label(self.lframe_settings_b, text='Meas. Set [A]')
self.label_set_time_b = Tkinter.Label(self.lframe_settings_b, text='Time Limit [s]')
self.label_set_delay_b = Tkinter.Label(self.lframe_settings_b, text='Measurement Delay [s]')
self.label_set_repeat_b = Tkinter.Label(self.lframe_settings_b, text='Repeat')
#C
self.label_power_supply_c = Tkinter.Label(self.lframe_instrumet_c, text="Power Supply 2200: ")
self.label_multimeter_c = Tkinter.Label(self.lframe_instrumet_c, text="Multimeter 2700: ")
self.label_voltage_range_c = Tkinter.Label(self.lframe_settings_c, text='Voltage Range [V]')
self.label_over_voltage_c = Tkinter.Label(self.lframe_settings_c, text='Over Voltage Protection [V]')
self.label_voltage_set_c = Tkinter.Label(self.lframe_settings_c, text='Set Voltage [V]')
self.label_heat_set_c = Tkinter.Label(self.lframe_settings_c, text='Heat.Set [A]')
self.label_meas_set_c = Tkinter.Label(self.lframe_settings_c, text='Meas. Set [A]')
self.label_set_time_c = Tkinter.Label(self.lframe_settings_c, text='Time Limit [s]')
self.label_set_delay_c = Tkinter.Label(self.lframe_settings_c, text='Measurement Delay [s]')
self.label_set_repeat_c = Tkinter.Label(self.lframe_settings_c, text='Repeat')
# Checkbutton
#A
self.temp_sensor_a_var = Tkinter.IntVar()
self.check_temp_sensor_a = Checkbutton(self.lframe_instrumet_a, text="Temperatursensor - #A", variable=self.temp_sensor_a_var,
onvalue=1, offvalue=0)
self.instrument_var_a = Tkinter.IntVar()
self.check_instrument_a = Checkbutton(self.lframe_settings_a, text="Instrument - #A", variable=self.instrument_var_a,
onvalue=1, offvalue=0)
#B
self.temp_sensor_b_var = Tkinter.IntVar()
self.check_temp_sensor_b = Checkbutton(self.lframe_instrumet_b, text="Temperatursensor - #B", variable=self.temp_sensor_b_var,
onvalue=1, offvalue=0)
self.instrument_var_b = Tkinter.IntVar()
self.check_instrument_b = Checkbutton(self.lframe_settings_b, text="Instrument - #B", variable=self.instrument_var_b,
onvalue=1, offvalue=0)
#C
self.temp_sensor_c_var = Tkinter.IntVar()
self.check_temp_sensor_c = Checkbutton(self.lframe_instrumet_c, text="Temperatursensor - #C", variable=self.temp_sensor_c_var,
onvalue=1, offvalue=0)
self.instrument_var_c = Tkinter.IntVar()
self.check_instrument_c = Checkbutton(self.lframe_settings_c, text="Instrument - #C", variable=self.instrument_var_c,
onvalue=1, offvalue=0)
# Entry/Spinbox
#A
self.voltage_range_a_var = Tkinter.IntVar()
self.spin_voltage_range_a = Tkinter.Spinbox(self.lframe_settings_a, textvariable=self.voltage_range_a_var, width=5,
from_=0, to=30, justify='right')
self.over_voltage_a_var = Tkinter.IntVar()
self.spin_over_voltage_a = Tkinter.Spinbox(self.lframe_settings_a, textvariable=self.over_voltage_a_var, width=5,
from_=0, to=30, justify='right')
self.heat_set_a_var = Tkinter.IntVar()
self.entry_heat_set_a = Tkinter.Entry(self.lframe_settings_a, textvariable=self.heat_set_a_var, width=7, justify='right')
self.meas_set_a_var = Tkinter.IntVar()
self.entry_meas_set_a = Tkinter.Entry(self.lframe_settings_a, textvariable=self.meas_set_a_var, width=7, justify='right')
self.voltage_set_a_var = Tkinter.IntVar()
self.entry_voltage_set_a = Tkinter.Entry(self.lframe_settings_a, textvariable=self.voltage_set_a_var, width=7, justify='right')
self.time_set_a_var = Tkinter.IntVar()
self.entry_time_set_a = Tkinter.Entry(self.lframe_settings_a, textvariable=self.time_set_a_var, width=7, justify='right')
self.delay_set_a_var = Tkinter.IntVar()
self.entry_delay_set_a = Tkinter.Entry(self.lframe_settings_a, textvariable=self.delay_set_a_var, width=7, justify='right')
self.repeat_set_a_var = Tkinter.IntVar()
self.entry_repeat_set_a = Tkinter.Entry(self.lframe_settings_a, textvariable=self.repeat_set_a_var, width=7, justify='right')
#B
self.voltage_range_b_var = Tkinter.IntVar()
self.spin_voltage_range_b = Tkinter.Spinbox(self.lframe_settings_b, textvariable=self.voltage_range_b_var, width=5,
from_=0, to=30, justify='right')
self.over_voltage_b_var = Tkinter.IntVar()
self.spin_over_voltage_b = Tkinter.Spinbox(self.lframe_settings_b, textvariable=self.over_voltage_b_var, width=5,
from_=0, to=30, justify='right')
self.heat_set_b_var = Tkinter.IntVar()
self.entry_heat_set_b = Tkinter.Entry(self.lframe_settings_b, textvariable=self.heat_set_b_var, width=7, justify='right')
self.meas_set_b_var = Tkinter.IntVar()
self.entry_meas_set_b = Tkinter.Entry(self.lframe_settings_b, textvariable=self.meas_set_b_var, width=7, justify='right')
self.voltage_set_b_var = Tkinter.IntVar()
self.entry_voltage_set_b = Tkinter.Entry(self.lframe_settings_b, textvariable=self.voltage_set_b_var, width=7, justify='right')
self.time_set_b_var = Tkinter.IntVar()
self.entry_time_set_b = Tkinter.Entry(self.lframe_settings_b, textvariable=self.time_set_b_var, width=7, justify='right')
self.delay_set_b_var = Tkinter.IntVar()
self.entry_delay_set_b = Tkinter.Entry(self.lframe_settings_b, textvariable=self.delay_set_b_var, width=7, justify='right')
self.repeat_set_b_var = Tkinter.IntVar()
self.entry_repeat_set_b = Tkinter.Entry(self.lframe_settings_b, textvariable=self.repeat_set_b_var, width=7, justify='right')
#C
self.voltage_range_c_var = Tkinter.IntVar()
self.spin_voltage_range_c = Tkinter.Spinbox(self.lframe_settings_c, textvariable=self.voltage_range_c_var, width=5,
from_=0, to=30, justify='right')
self.over_voltage_c_var = Tkinter.IntVar()
self.spin_over_voltage_c = Tkinter.Spinbox(self.lframe_settings_c, textvariable=self.over_voltage_c_var, width=5,
from_=0, to=30, justify='right')
self.heat_set_c_var = Tkinter.IntVar()
self.entry_heat_set_c = Tkinter.Entry(self.lframe_settings_c, textvariable=self.heat_set_c_var, width=7, justify='right')
self.meas_set_c_var = Tkinter.IntVar()
self.entry_meas_set_c = Tkinter.Entry(self.lframe_settings_c, textvariable=self.meas_set_c_var, width=7, justify='right')
self.voltage_set_c_var = Tkinter.IntVar()
self.entry_voltage_set_c = Tkinter.Entry(self.lframe_settings_c, textvariable=self.voltage_set_c_var, width=7, justify='right')
self.time_set_c_var = Tkinter.IntVar()
self.entry_time_set_c = Tkinter.Entry(self.lframe_settings_c, textvariable=self.time_set_c_var, width=7, justify='right')
self.delay_set_c_var = Tkinter.IntVar()
self.entry_delay_set_c = Tkinter.Entry(self.lframe_settings_c, textvariable=self.delay_set_c_var, width=7, justify='right')
self.repeat_set_c_var = Tkinter.IntVar()
self.entry_repeat_set_c = Tkinter.Entry(self.lframe_settings_c, textvariable=self.repeat_set_c_var, width=7, justify='right')
# Button
self.button_run = Tkinter.Button(self.frame_settings, text="Run", command=lambda: self.on_run(), width=25)
self.button_stop = Tkinter.Button(self.frame_settings, text="Stop", command=lambda: self.on_stop(), width=25)
self.button_quit = Tkinter.Button(self.frame_settings, text="Quit", command=lambda: self.on_quit(), width=25)
# Grid
parent.resizable(False, False)
parent.grid_columnconfigure(0, weight=0)
# Instrument #A
self.frame_instruments.grid(row=0, column=0)
self.lframe_instrumet_a.grid(row=0, column=0)
self.label_power_supply_a.grid(row=0, column=0, sticky='W')
self.label_multimeter_a.grid(row=1, column=0, sticky='W')
self.combo_power_supply_a.grid(row=0, column=1)
self.combo_multimeter_a.grid(row=1, column=1)
self.check_temp_sensor_a.grid(row=2, column=1)
self.lframe_settings_a.grid(row=0, column=2)
self.label_voltage_range_a.grid(row=0, column=2, sticky='W')
self.spin_voltage_range_a.grid(row=0, column=3)
self.label_over_voltage_a.grid(row=1, column=2, sticky='W')
self.label_heat_set_a.grid(row=2, column=2, sticky='W')
self.spin_over_voltage_a.grid(row=1, column=3)
self.entry_heat_set_a.grid(row=2, column=3)
self.label_voltage_set_a.grid(row=0, column=4, sticky='W')
self.label_meas_set_a.grid(row=1, column=4, sticky='W')
self.label_set_time_a.grid(row=2, column=4, sticky='W')
self.entry_voltage_set_a.grid(row=0, column=5)
self.entry_meas_set_a.grid(row=1, column=5)
self.entry_time_set_a.grid(row=2, column=5)
self.label_set_delay_a.grid(row=0, column=6, sticky='W')
self.label_set_repeat_a.grid(row=1, column=6, sticky='W')
self.entry_delay_set_a.grid(row=0, column=7)
self.entry_repeat_set_a.grid(row=1, column=7)
self.check_instrument_a.grid(row=2, column=6, sticky='W')
# Instrument #B
self.lframe_instrumet_b.grid(row=3)
self.label_power_supply_b.grid(row=3, column=0)
self.label_multimeter_b.grid(row=4, column=0)
self.combo_power_supply_b.grid(row=3, column=1)
self.combo_multimeter_b.grid(row=4, column=1)
self.check_temp_sensor_b.grid(row=5, column=1)
self.lframe_settings_b.grid(row=3, column=2)
self.label_voltage_range_b.grid(row=3, column=2, sticky='W')
self.spin_voltage_range_b.grid(row=3, column=3)
self.label_over_voltage_b.grid(row=4, column=2, sticky='W')
self.label_heat_set_b.grid(row=5, column=2, sticky='W')
self.spin_over_voltage_b.grid(row=4, column=3)
self.entry_heat_set_b.grid(row=5, column=3)
self.label_voltage_set_b.grid(row=3, column=4, sticky='W')
self.label_meas_set_b.grid(row=4, column=4, sticky='W')
self.label_set_time_b.grid(row=5, column=4, sticky='W')
self.entry_voltage_set_b.grid(row=3, column=5)
self.entry_meas_set_b.grid(row=4, column=5)
self.entry_time_set_b.grid(row=5, column=5)
self.label_set_delay_b.grid(row=3, column=6, sticky='W')
self.label_set_repeat_b.grid(row=4, column=6, sticky='W')
self.entry_delay_set_b.grid(row=3, column=7)
self.entry_repeat_set_b.grid(row=4, column=7)
self.check_instrument_b.grid(row=5, column=6, sticky='W')
# Instrument #C
self.lframe_instrumet_c.grid(row=6)
self.label_power_supply_c.grid(row=6, column=0)
self.label_multimeter_c.grid(row=7, column=0)
self.combo_power_supply_c.grid(row=6, column=1)
self.combo_multimeter_c.grid(row=7, column=1)
self.check_temp_sensor_c.grid(row=8, column=1)
self.lframe_settings_c.grid(row=6, column=2)
self.label_voltage_range_c.grid(row=6, column=2, sticky='W')
self.spin_voltage_range_c.grid(row=6, column=3)
self.label_over_voltage_c.grid(row=7, column=2, sticky='W')
self.label_heat_set_c.grid(row=8, column=2, sticky='W')
self.spin_over_voltage_c.grid(row=7, column=3)
self.entry_heat_set_c.grid(row=8, column=3)
self.label_voltage_set_c.grid(row=6, column=4, sticky='W')
self.label_meas_set_c.grid(row=7, column=4, sticky='W')
self.label_set_time_c.grid(row=8, column=4, sticky='W')
self.entry_voltage_set_c.grid(row=6, column=5)
self.entry_meas_set_c.grid(row=7, column=5)
self.entry_time_set_c.grid(row=8, column=5)
self.label_set_delay_c.grid(row=6, column=6, sticky='W')
self.label_set_repeat_c.grid(row=7, column=6, sticky='W')
self.entry_delay_set_c.grid(row=6, column=7)
self.entry_repeat_set_c.grid(row=7, column=7)
self.check_instrument_c.grid(row=8, column=6, sticky='W')
# Button
self.frame_settings.grid(row=8)
self.button_run.grid(row=8, column=0)
self.button_stop.grid(row=8,column=1)
self.button_quit.grid(row=8, column=2)
# Function
def about(self):
tkMessageBox.showinfo("About", "About" %chr(64))
def on_quit(self):
self.parent.quit()
self.parent.destroy()
self.fout.close()
def save_file(self):
self.file_opt = self.options = {}
self.options['filetypes'] = [('Text Files', '.txt')]
self.dataname = asksaveasfilename(**self.file_opt)
self.datamode = 'a'
try:
self.fout = open(self.dataname, self.datamode)
except Exception, e:
strError = "Output file open error: "+ str(e)
tkMessageBox.showerror("Error", strError)
def on_stop(self):
self.button_quit.configure(state='active')
def on_run(self):
self.button_quit.configure(state='disable')
create_header = Header(gui.fout, self.selected_instruments_query(),self.dataname, self.voltage_range_a_var.get(),
self.voltage_set_a_var.get(), self.delay_set_a_var.get(), self.over_voltage_a_var.get(),
self.meas_set_a_var.get(), self.repeat_set_a_var.get(), self.heat_set_a_var.get(),
self.temp_sensor_a_var.get(), self.voltage_range_b_var.get(),
self.voltage_set_b_var.get(), self.delay_set_b_var.get(), self.over_voltage_b_var.get(),
self.meas_set_b_var.get(), self.repeat_set_b_var.get(), self.heat_set_b_var.get(),
self.temp_sensor_b_var.get(),self.voltage_range_c_var.get(),
self.voltage_set_c_var.get(), self.delay_set_c_var.get(), self.over_voltage_c_var.get(),
self.meas_set_c_var.get(), self.repeat_set_c_var.get(), self.heat_set_c_var.get(),
self.temp_sensor_c_var.get())
def selected_instruments_query(self):
selected_power_query = [self.instrument_var_a.get(), self.instrument_var_b.get(), self.instrument_var_c.get()]
selected_multimeter_query = [self.temp_sensor_a_var.get(), self.temp_sensor_b_var.get(), self.temp_sensor_c_var.get()]
selected_instruments_query = [selected_power_query,selected_multimeter_query]
return selected_instruments_query
class Header:
WRITE = 0
def __init__(self,fout,selected_instruments,dataname,voltage_range_a_var,voltage_set_a_var, delay_set_a_var,
over_voltage_a_var,meas_set_a_var, repeat_set_a_var, heat_set_a_var, time_set_a_var, voltage_range_b_var,
voltage_set_b_var, delay_set_b_var,over_voltage_b_var,meas_set_b_var, repeat_set_b_var,
heat_set_b_var, time_set_b_var, voltage_range_c_var,voltage_set_c_var, delay_set_c_var,
over_voltage_c_var,meas_set_c_var, repeat_set_c_var, heat_set_c_var, time_set_c_var):
self.fout = fout
self.selected_instruments = selected_instruments
self.dataname = dataname
self.voltage_range_a_var = voltage_range_a_var
self.voltage_set_a_var = voltage_set_a_var
self.delay_set_a_var = delay_set_a_var
self.over_voltage_a_var = over_voltage_a_var
self.meas_set_a_var = meas_set_a_var
self.repeat_set_a_var = repeat_set_a_var
self.heat_set_a_var = heat_set_a_var
self.time_set_a_var = time_set_a_var
self.voltage_range_b_var = voltage_range_b_var
self.voltage_set_b_var = voltage_set_b_var
self.delay_set_b_var = delay_set_b_var
self.over_voltage_b_var = over_voltage_b_var
self.meas_set_b_var = meas_set_b_var
self.repeat_set_b_var = repeat_set_b_var
self.heat_set_b_var = heat_set_b_var
self.time_set_b_var = time_set_b_var
self.voltage_range_c_var = voltage_range_c_var
self.voltage_set_c_var = voltage_set_c_var
self.delay_set_c_var = delay_set_c_var
self.over_voltage_c_var = over_voltage_c_var
self.meas_set_c_var = meas_set_c_var
self.repeat_set_c_var = repeat_set_c_var
self.heat_set_c_var = heat_set_c_var
self.time_set_c_var = time_set_c_var
print self.selected_instruments
# Header involve data only once
if Header.WRITE == 0:
self.header_file()
Header.WRITE = 1
def header_file(self):
t = datetime.datetime.now()
curr_datetime = t.timetuple()
yr = str(curr_datetime[0])
curr_date = "%02d."%int(yr[2:]) + "%02d."%curr_datetime[1] + "%02d."%curr_datetime[2]
curr_time = "%02d:"%curr_datetime[3] + "%02d:"%curr_datetime[4] + "%02d"%curr_datetime[5]
time_data = curr_date + " " + curr_time
separate_line = "*"*120
str_out_time = "Filename: \t%s \nTime/Date: \t%s \n\nInstrument - #A\n\n" % (self.dataname, time_data)
self.fout.write(str_out_time)
str_out_a = "Voltage Range: \t%d\tSet Voltage: \t%d\tMeasurement Delay: \t%d\n" \
"OVP: \t\t%d\tMeas.Set: \t%d\tRepeat: \t\t%d\n" \
"Heat.Set: \t%d\tTime Limit: \t%d\n\n\n" % (self.voltage_range_a_var,
self.voltage_set_a_var, self.delay_set_a_var, self.over_voltage_a_var,
self.meas_set_a_var, self.repeat_set_a_var, self.heat_set_a_var,
self.time_set_a_var)
str_out_b = "Instrument - #B\n\nVoltage Range: \t%d\tSet Voltage: \t%d\tMeasurement Delay: \t%d\n" \
"OVP: \t\t%d\tMeas.Set: \t%d\tRepeat: \t\t%d\n" \
"Heat.Set: \t%d\tTime Limit: \t%d\n\n\n" % (self.voltage_range_b_var,
self.voltage_set_b_var, self.delay_set_b_var, self.over_voltage_b_var,
self.meas_set_b_var, self.repeat_set_b_var, self.heat_set_b_var,
self.time_set_b_var)
str_out_c = "Instrument - #C\n\nVoltage Range: \t%d\tSet Voltage: \t%d\tMeasurement Delay: \t%d\n" \
"OVP: \t\t%d\tMeas.Set: \t%d\tRepeat: \t\t%d\n" \
"Heat.Set: \t%d\tTime Limit: \t%d\n\n\n%s\n" % (self.voltage_range_c_var,
self.voltage_set_c_var, self.delay_set_c_var, self.over_voltage_c_var,
self.meas_set_c_var, self.repeat_set_c_var, self.heat_set_c_var,
self.time_set_c_var, separate_line)
# Print header file depending of the instruments
for condition, string in zip(self.selected_instruments[0], [str_out_a, str_out_b, str_out_c]):
if condition:
self.fout.write(string)
if __name__ == '__main__':
root = Tkinter.Tk()
gui = Interface(root)
root.mainloop()
A terrifyingly simplified example of how you can use (and toggle) three different loops, running in parallel, (in this case) printing three different words.
Using Tkinters's after() method, these loops can run inside the main loop:
from Tkinter import *
class MultiLoop:
def __init__(self):
self.master = Tk()
self.run1 = False
self.run2 = False
self.run3 = False
button1 = Button(text="Toggle Monkey", command = self.togglemonkey).pack()
button2 = Button(text="Toggle eats", command = self.toggleeats).pack()
button3 = Button(text="Toggle banana", command = self.togglebanana).pack()
# first call:
self.master.after(0, self.loop1)
self.master.after(0, self.loop2)
self.master.after(0, self.loop3)
self.master.mainloop()
# The three loops
def loop1(self):
if self.run1 == True:
print("Monkey")
else:
pass
# schedule next run
self.master.after(100, self.loop1)
def loop2(self):
if self.run2 == True:
print("eats")
else:
pass
# schedule next run
self.master.after(1000, self.loop2)
def loop3(self):
if self.run3 == True:
print("banana")
else:
pass
# schedule next run
self.master.after(2000, self.loop3)
# The toggle functions
def togglemonkey(self):
self.run1 = True if self.run1 == False else False
def toggleeats(self):
self.run2 = True if self.run2 == False else False
def togglebanana(self):
self.run3 = True if self.run3 == False else False
MultiLoop()

Calling lists when lists when lists are empty in TKinter

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()

Categories

Resources