Run function in form (ctd) - python-3.x

Here's my current code and the changes I've made so far from the previous version
I've reset the variables at the start because I did not want them to be reset each time the function was executed
I've added a ess_e variable for the entry of the procedure, I want this variable to store the localtime when the function is executed
I've added a ess_s variable for the exit of the procedure after all the infos are entered which should be localtime when the submit button (changed text) is pushed
The remaining problems are
root.bind does not work, I've tried several alternatives with fenetre as you suggested but I could not make it work.
I get an error when I run the 2nd function (essenceresult)
File "D:\Bureautique\Python\Scripts\interface-test.py", line 57, in essenceResult
ess_e = ent0.get()
AttributeError: 'datetime.datetime' object has no attribute 'get'
I still have to make the frame to display the previous results but I'll get there in due time :)
Thanks a lot for the help
from tkinter import *
from datetime import *
import time
ess=[[],[],[],[],[]]
rel=[[],[],[],[],[]]
c60=[[],[]]
def c60duree(delta):
(h, r) = divmod(delta.seconds, 3600)
(m, s) = divmod(r, 60)
return "%s%02d:%02d:%02d" % (
"%d jour(s) " % delta.days if delta.days > 0 else "",
h,
m,
s,
)
def code60():
saisie=0
while saisie != "X":
c60d=datetime.now()
print ("Code 60 activé à ", c60d.strftime("%H:%M:%S"))
saisie=input("Tapez entree pour la fin du code 60, X pour sortir : ")
c60f=datetime.now()
print("Debut ", c60d.strftime("%H:%M:%S"))
print("Fin ", c60f.strftime("%H:%M:%S"))
c60x=c60f-c60d
print("Duree ", c60duree(c60x))
print("-------------")
c60[0].append(c60d)
c60[1].append(c60f)
#del(c60[0],[-1])
#del(c60[1],[-1])
#return
def relais():
print("Relais pilote demarré ")
relh=datetime.now()
relv=input("Quelle voiture ? ")
relp=input("Quel pilote repart ? ")
rele=input("Quantité d'essence ? ")
input("Tapez entrée à la sortie des stands ")
rels=datetime.now()
rel[0].append(relh), rel[1].append(relv), rel[2].append(relp), rel[3].append(rele), rel[4].append(rels)
print("Dureé ", rels-relh)
print(*rel)
#def essence():
#ess=[[],[],[],[]]
#print("Ravitaillement essence demarré ")
#essh=datetime.now()
#essv=input("Quelle voiture ? ")
#essp=input("Quel pilote ? ")
#essq=input("Combien de litres ? ")
#ess[0].append(essh), ess[1].append(essv), ess[2].append(essp), ess[3].append(essq)
#print(*ess)
def essenceResult(ess, ent0, ent1, ent2, ent3):
ess_e = ent0.get()
essv = ent1.get()
essp = ent2.get()
essq = ent3.get()
ess_s = datetime.now()
ess[0].append(ess_e), ess[1].append(essv), ess[2].append(essp), ess[3].append(essq), ess [4].append(ess_s)
resultLabel = Label(Frame4, text = str(*ess))
resultLabel.grid(row = 5, column = 0, columnspan = 2)
def essence():
print("yr")
ess_e=datetime.now()
Frame4.grid(row = 1, column = 0)
Label1 = Label(Frame4, text = "Ravitaillement demarré ")
Label1.grid(row = 0, column = 0, columnspan = 2)
essvLabel = Label(Frame4, text = "Quelle voiture ? ")
essvEntry = Entry(Frame4)
essvLabel.grid(row = 1, column = 0)
essvEntry.grid(row = 1, column = 1)
essvEntry.focus()
#root.bind_all("<Return>", function)
esspLabel = Label(Frame4, text = "Quel pilote part ? ")
esspEntry = Entry(Frame4)
esspLabel.grid(row = 2, column = 0)
esspEntry.grid(row = 2, column = 1)
esspEntry.focus()
essqLabel = Label(Frame4, text = "Combien de litres ? ")
essqEntry = Entry(Frame4)
essqLabel.grid(row = 3, column = 0)
essqEntry.grid(row = 3, column = 1)
essqEntry.focus()
submitButton = Button(Frame4, text = "Sortie des stands", command = lambda: essenceResult(ess, ess_e, essvEntry, esspEntry, essqEntry))
submitButton.grid(row = 4, column = 0, columnspan = 2)
fenetre = Tk()
fenetre['bg']='grey'
# frame 1
Frame1 = Frame(fenetre, bg="green", borderwidth=1, relief=GROOVE)
Frame1.grid(row = 0, column = 0, padx=5, pady=5)
# frame 2
Frame2 = Frame(fenetre, bg="yellow", borderwidth=1, relief=GROOVE)
Frame2.grid(row = 0, column = 1, padx=5, pady=5)
# frame 3
Frame3 = Frame(fenetre, bg="purple", borderwidth=1, relief=GROOVE)
Frame3.grid(row = 0, column = 2, padx=5, pady=5)
Frame4 = Frame(fenetre)
Fenetre = Tk()
fenetre['bg']='grey'
# Ajout de labels
Button(Frame1, text="Essence", command=essence).pack(padx=300, pady=100)
Button(Frame2, text="Relais", command=relais).pack(padx=300, pady=100)
Button(Frame3, text="Code 60", command=code60).pack(padx=300, pady=100)

Here's the fixed code:
def essenceResult(ess, ess_e, ent1, ent2, ent3):
essv = ent1.get()
essp = ent2.get()
essq = ent3.get()
ess_s = datetime.now()
ess[0].append(ess_e), ess[1].append(essv), ess[2].append(essp), ess[3].append(essq), ess[4].append(ess_s)
resultLabel = Label(Frame4, text = str(ess))
resultLabel.grid(row = 5, column = 0, columnspan = 2)
def essence():
print("yr")
ess_e=datetime.now()
Frame4.grid(row = 1, column = 0)
Label1 = Label(Frame4, text = "Ravitaillement demarré ")
Label1.grid(row = 0, column = 0, columnspan = 2)
essvLabel = Label(Frame4, text = "Quelle voiture ? ")
essvEntry = Entry(Frame4)
essvLabel.grid(row = 1, column = 0)
essvEntry.grid(row = 1, column = 1)
essvEntry.focus()
esspLabel = Label(Frame4, text = "Quel pilote part ? ")
esspEntry = Entry(Frame4)
esspLabel.grid(row = 2, column = 0)
esspEntry.grid(row = 2, column = 1)
esspEntry.focus()
essqLabel = Label(Frame4, text = "Combien de litres ? ")
essqEntry = Entry(Frame4)
essqLabel.grid(row = 3, column = 0)
essqEntry.grid(row = 3, column = 1)
essqEntry.focus()
submitCommand = lambda event = None: essenceResult(ess, ess_e, essvEntry, esspEntry, essqEntry)
submitButton = Button(Frame4, text = "Sortie des stands", command = submitCommand)
Frame4.bind_all("<Return>", submitCommand)
submitButton.grid(row = 4, column = 0, columnspan = 2)
You also need to remove the extra Fenetre = Tk() after Frame4, as this will break it. (You can only have one Tk(), if you want more windows use Toplevel())The first problem is solved by adding Frame4.bind_all("<Return>", submitCommand). Now when you press enter it will run submitCommand, which will run essenceResult.
The second problem was using .get() on a datetime.datetime object. You can't use .get() because it isn't an entry. Instead, just have it as a parameter and don't change it. You only need .get() to get the values from a Tkinter Entry.

Related

run a function from a button in a frame

I'm just starting with python 3, I've made 3 scripts which do what I want them to do and now I'm trying to include them in a very basic GUI that I made with tinker.
I've joined my 3 scripts into a single file and made a function of each of them
Basically I'd like to run this or that function when I click on a button in the frame.
The problem is that of course I d'ont know how to do it, can someone point me in the right direction ?
Thanks for the help.
from tkinter import *
from datetime import *
import time
def c60duree(delta):
(h, r) = divmod(delta.seconds, 3600)
(m, s) = divmod(r, 60)
return "%s%02d:%02d:%02d" % (
"%d jour(s) " % delta.days if delta.days > 0 else "",
h,
m,
s,
)
def code60():
saisie=0
c60=[[],[]]
while saisie != "X":
c60d=datetime.now()
print ("Code 60 activé à ", c60d.strftime("%H:%M:%S"))
saisie=input("Tapez entree pour la fin du code 60, X pour sortir : ")
c60f=datetime.now()
print("Debut ", c60d.strftime("%H:%M:%S"))
print("Fin ", c60f.strftime("%H:%M:%S"))
c60x=c60f-c60d
print("Duree ", c60duree(c60x))
print("-------------")
c60[0].append(c60d)
c60[1].append(c60f)
#del(c60[0],[-1])
#del(c60[1],[-1])
#return
def relais():
rel=[[],[],[],[],[]]
print("Relais pilote demarré ")
relh=datetime.now()
relv=input("Quelle voiture ? ")
relp=input("Quel pilote repart ? ")
rele=input("Quantité d'essence ? ")
input("Tapez entrée à la sortie des stands ")
rels=datetime.now()
rel[0].append(relh), rel[1].append(relv), rel[2].append(relp), rel[3].append(rele), rel[4].append(rels)
print("Dureé ", rels-relh)
print(*rel)
def essence():
ess=[[],[],[],[]]
print("Ravitaillement essence demarré ")
essh=datetime.now()
essv=input("Quelle voiture ? ")
essp=input("Quel pilote ? ")
essq=input("Combien de litres ? ")
ess[0].append(essh), ess[1].append(essv), ess[2].append(essp), ess[3].append(essq)
print(*ess)
fenetre = Tk()
fenetre['bg']='grey'
# frame 1
Frame1 = Frame(fenetre, bg="yellow", borderwidth=1, relief=GROOVE)
Frame1.pack(side=LEFT, padx=5, pady=5)
# frame 2
Frame2 = Frame(fenetre, bg="green", borderwidth=1, relief=GROOVE)
Frame2.pack(side=LEFT, padx=5, pady=5)
# frame 3
Frame3 = Frame(fenetre, bg="red", borderwidth=1, relief=GROOVE)
Frame3.pack(side=LEFT, padx=5, pady=5)
# Ajout de labels
Label(Frame1, text="Essence").pack(padx=300, pady=100)
Label(Frame2, text="Relais").pack(padx=300, pady=100)
Label(Frame3, text="C60").pack(padx=300, pady=100)
If you want to continue using Labels, you can bind a function to them like this:
# Ajout de labels
label1 = Label(Frame1, text="Essence")
label1.bind("<Button-1>", lambda event: essence())
label1.pack(padx=300, pady=100)
label2 = Label(Frame2, text="Relais")
label2.bind("<Button-1>", lambda event: relais())
label2.pack(padx=300, pady=100)
label3 = Label(Frame3, text="C60")
label3.bind("<Button-1>", lambda event: code60())
label3.pack(padx=300, pady=100)
I've had to give the labels each a name so I could add the binding. The bind method takes a key and a function. The key I've given is Button-1, which is the left mouse button. Therefore when you click on the label the function is run. When you bind a function, and extra argument called event is added. For this example we don't need event, so I've used lambda event: to essentially ignore it and call the function like normal.
Another way you could do this is with buttons:
# Ajout de labels
Button(Frame1, text="Essence", command = essence).pack(padx=300, pady=100)
Button(Frame2, text="Relais", command = relais).pack(padx=300, pady=100)
Button(Frame3, text="C60", command = code60).pack(padx=300, pady=100)
This is a lot more straightforward but looks different to a Label.
EDIT
To make the text appear in the GUI, you could do something like this:
def essenceResult(ess, ent1, ent2, ent3):
essh=datetime.now()
essv = ent1.get()
essp = ent2.get()
essq = ent3.get()
ess[0].append(essh), ess[1].append(essv), ess[2].append(essp), ess[3].append(essq)
resultLabel = Label(Frame4, text = str(ess))
resultLabel.grid(row = 5, column = 0, columnspan = 2)
def essence():
print("yr")
Frame4.grid(row = 1, column = 0)
ess=[[],[],[],[]]
Label1 = Label(Frame4, text = "Ravitaillement essence demarré ")
Label1.grid(row = 0, column = 0, columnspan = 2)
essvLabel = Label(Frame4, text = "Quelle voiture ? ")
essvEntry = Entry(Frame4)
essvLabel.grid(row = 1, column = 0)
essvEntry.grid(row = 1, column = 1)
esspLabel = Label(Frame4, text = "Quel pilote ? ")
esspEntry = Entry(Frame4)
esspLabel.grid(row = 2, column = 0)
esspEntry.grid(row = 2, column = 1)
essqLabel = Label(Frame4, text = "Combien de litres ? ")
essqEntry = Entry(Frame4)
essqLabel.grid(row = 3, column = 0)
essqEntry.grid(row = 3, column = 1)
submitButton = Button(Frame4, text = "Submit", command = lambda: essenceResult(ess, essvEntry, esspEntry, essqEntry))
submitButton.grid(row = 4, column = 0, columnspan = 2)
fenetre = Tk()
fenetre['bg']='grey'
# frame 1
Frame1 = Frame(fenetre, bg="yellow", borderwidth=1, relief=GROOVE)
Frame1.grid(row = 0, column = 0, padx=5, pady=5)
# frame 2
Frame2 = Frame(fenetre, bg="green", borderwidth=1, relief=GROOVE)
Frame2.grid(row = 0, column = 1, padx=5, pady=5)
# frame 3
Frame3 = Frame(fenetre, bg="red", borderwidth=1, relief=GROOVE)
Frame3.grid(row = 0, column = 2, padx=5, pady=5)
Frame4 = Frame(fenetre)
Frame4 is used to show the things for essence, but is not displayed until the user presses the button. The inputs have been replaced with a label for the question and an entry for the user to put their answer. Then when they press submit, the essenceResult function adds a label with what the print function used to show.

Problem with dynamically changing which command a button calls in tkinter

In this simple calculator GUI, I'm creating a frame template using classes. The frame has 2 labels, 2 entry boxes, and a button. I'd like the button to run a specific command depending on the function_call variable passed when initializing - but this doesn't work. The two_points function should be called for the first object, and one_point should be called for the second. How do I dynamically change which command is called based on which object I'm using? Thank you for taking the time to read this.
from tkinter import *
root = Tk()
root.title("Simple Slope Calculator")
class Slope_Calc:
# Variable info that changes within the frame
def __init__(self, master, num_1, num_2, frame_name, label_1_name, label_2_name, function_call):
self.num_1 = int(num_1)
self.num_2 = int(num_2)
self.frame_name = frame_name
self.label_1_name = label_1_name
self.label_2_name = label_2_name
self.function_call = function_call
# Frame template
self.frame_1 = LabelFrame(master, text = self.frame_name, padx = 5, pady = 5)
self.frame_1.grid(row = self.num_1, column = self.num_2, padx = 10, pady = 10)
self.label_1 = Label(self.frame_1, text = self.label_1_name)
self.label_1.grid(row = 0, column = 0)
self.entry_1 = Entry(self.frame_1)
self.entry_1.grid(row = 0, column = 1)
self.label_2 = Label(self.frame_1, text = self.label_2_name)
self.label_2.grid(row = 1, column = 0)
self.entry_2 = Entry(self.frame_1)
self.entry_2.grid(row = 1, column = 1)
self.calc_button = Button(self.frame_1, text = "Calculate", command = self.function_call) # This is what doesn't work
self.calc_button.grid(row = 1, column = 2, padx = 5)
# Strips string of spaces and parentheses
# Returns a list of relevant ordered pair
def strip_string(self, entry_num):
ordered_pair = entry_num.get().split(", ")
ordered_pair[0] = ordered_pair[0].replace("(", "")
ordered_pair[1] = ordered_pair[1].replace(")", "")
return(ordered_pair)
# Calculates slope based on one point and y-intercept
def one_point(self):
pair_1 = self.strip_string(self.entry_1)
b = int(self.entry_2.get())
m = (int(pair_1[1]) - b)/(float(pair_1[1]))
label_3 = Label(self.frame_1, text = "SLOPE-INTERCEPT EQUATION: y = " + str(m) + "x + " + str(b))
label_3.grid(row = 2, column = 0, columnspan = 2)
# Calculates slope based on two points given
def two_points(self):
pair_1 = self.strip_string(self.entry_1)
pair_2 = self.strip_string(self.entry_2)
m = (int(pair_2[1]) - int(pair_1[1]))/float(int(pair_2[0]) - int(pair_1[0]))
b = (int(pair_1[1])) - (m*int(pair_1[0]))
label_3 = Label(self.frame_1, text = "SLOPE-INTERCEPT EQUATION: y = " + str(m) + "x + " + str(b))
label_3.grid(row = 2, column = 0, columnspan = 2)
# Calling each object
two_p = Slope_Calc(root, 0, 0, "Two Points", "First Ordered Pair", "Second Ordered Pair", "two_points")
one_p = Slope_Calc(root, 0, 1, "One Point and Y-Intercept", "Ordered Pair", "Y-intercept", "one_point")
root.mainloop()
The command keyword argument of the Button constructor is supposed to be a function.
Here you give it instead a string which is the name of the method of self that should be called. So you must first get this method using setattr to be able to call it. This should do it:
def call():
method = getattr(self, self.function_call)
method()
self.calc_button = Button(
self.frame_1,
text = "Calculate",
command = call)
You then have an error in strip_string but that's another story.

Changing a variable with a button (and a function) in Python Tkinter

I have the following code (it's partly in Dutch but I don't think that'll be an issue):
from tkinter import *
root = Tk()
woorden_en = ["mouse", "armadillo", "caterpillar", "buffalo", "dragonfly", "eel", "monkey", "lark", "manatee", "squid"]
woorden_nl = ["muis", "gordeldier", "rups", "buffel", "libelle", "paling", "aap", "leeuwerik", "zeekoe", "inktvis"]
nummer = IntVar()
nlWoord = StringVar()
enWoord = StringVar()
goedfout = StringVar()
def vorige():
nummer -= 1
def volgende():
nummer += 1
def controleer():
print("Correct!")
secondGrid = Frame(root)
secondGrid.grid(row = 2, column = 1, columnspan = 2)
labelVertaling = Label(root, text="vertaling")
textVertaling = Entry(root, width=30, textvariable = nlWoord)
runVorige = Button(secondGrid, text="vorige", command = vorige)
runVolgende = Button(secondGrid, text="volgende", command = volgende)
runControleer = Button(secondGrid, text="controleer", command = controleer)
labelWoord = Label(root, text="woord")
labelWoordEn = Label(root, textvariable = enWoord)
labelNo = Label(root, textvariable = nummer)
Correct = Label(root, textvariable = goedfout)
Correct.grid(row = 2, column = 0)
labelNo.grid(row = 0, column = 0)
labelWoord.grid(row = 0, column = 1)
labelWoordEn.grid(row = 1, column = 1)
labelVertaling.grid(row = 0, column = 2)
textVertaling.grid(row = 1, column = 2)
runVorige.grid(row = 0, column = 0, sticky = "W")
runVolgende.grid(row = 0, column = 1, sticky = "W")
runControleer.grid(row = 0, column = 2, sticky = "W")
nummer.set(1)
enWoord.set(woorden_en[0])
root.mainloop()
The start value of 'nummer' is 1, as set in the 3rd to last line. This value needs to be changed with either -1 or +1 when clicking buttons 'vorige' (previous) or 'volgende' (next). The current code in the functions give me erros. Apparently I need to use set/get functions, but I cannot find out how to make it work. Any input or help would be appreciated.
Just change your function to:
def vorige():
nummer_val = nummer.get()
nummer_val -= 1
nummer.set(nummer_val)
def volgende():
nummer_val = nummer.get()
nummer_val += 1
nummer.set(nummer_val)
This is because nummer is an IntVar() and you have to get the value of the variable using get() method. After that you have to assign it to a variable and then reduce/increase its value by 1. The first error you were getting was because the nummer was not globalized inside the function, but that was not the approach you should have taken, anyway this should fix your errors.

My python program works on Linux but not on Widows?

So my program compares images and deletes any that are the same, renaming the original to how many were deleted. This program works fine on my Linux (ubuntu) but when used on my Windows 8 laptop I get the error at the bottom, any advice is greatly appreciated.
PIL.UnidentifiedImageError: cannot identify image file 'C:\\Users\\Public\\Pictures\\Sample Pictures/desktop.ini'
(there is more to the error code if you need it, also I import os, send2trash, pil, shutil and tkinter to use with the script)
import os
from PIL import ImageChops, ImageDraw
import PIL.Image
import shutil
from send2trash import send2trash
from tkinter import *
root = Tk()
root.title("Cupcake 3.0")
paths = Entry(root, width = 50, borderwidth = 5)
paths.grid(row = 2, column =2, columnspan =3)
path = paths.get()
def add():
end_image = PIL.Image.new(mode = "RGB",size = (200, 70), color = "red")
end_image.save(paths.get() +"/zzz999.png")
files = os.listdir(paths.get())
files.sort()
image1 =files[0]
counter = 1
im1 = " "
for file in files:
original_file_name, file_ext = (os.path.splitext(file))
if delete == 0:
ofn, fe = (os.path.splitext(image1))
if image1 == file:
pass
elif image1 != file:
im1 = PIL.Image.open(paths.get() + "/" + image1).histogram() #the image to be compared too
im2 = PIL.Image.open(paths.get() + "/" + file).histogram()#file for comparison
if im1 == im2:
send2trash(paths.get() + "/" +file)
counter = counter +1
elif im1 != im2:
os.rename(paths.get() + "/" + image1, paths.get() + "/" + ofn + "_X" +str(counter)+ fe)
counter = 1
image1 = file
else:
print("something went wrong")
else:
addd = input("Enter in the text you wish to be added/removed (can not contain blank spaces): ").strip()
new_name = "{}{}{}".format(original_file_name, addd, file_ext).strip()
os.rename(path + "/" + file, path + "/" + new_name)
print("Job Complete")
send2trash(paths.get() + "/zzz999.png")
welcome = Label(root, text = "Welcome to Cupcake 3.0")
welcome.grid(row = 0, column =2, columnspan =3)
l1 = Label (root, text = "Please enter the path to your folder: ")
l1.grid(row = 1, column =2, columnspan =3)
paths = Entry(root, width = 50, borderwidth = 5)
paths.grid(row = 2, column =2, columnspan =3)
path = paths.get()
d = IntVar()
Radiobutton(root, text = "Add", variable = d, value = 1, anchor = W).grid(row = 3, column = 2, sticky = W)
Radiobutton(root, text = "Remove", variable = d, value = 2,anchor = W).grid(row = 4, column = 2, sticky = W)
def_question = d.get()
l2 = Label (root, text = "Enter text you want removed (leave blank if n/a): ").grid(row = 6, column = 2)
rem = Entry(root, width = 50, borderwidth = 5)
rem.grid(row = 7, column =2, columnspan =3)
remo=rem.get().strip()
de = IntVar()
c = Checkbutton(root, text = "Do you wish to delete duplicate files?", variable = de)
c.grid(row = 8, column =2, sticky = W)
delete = de.get()
def run():
#print(d.get())
#print(def_question)
if d.get() == 1:
add()
elif d.get() == 2:
remove()
else:
print("I don't understand your command")
def remove():
files = os.listdir(paths.get())
files.sort()
for file in files:
original_file_name, file_ext = (os.path.splitext(file))
#print(remo)
new_name = original_file_name.replace(rem.get(), "").strip()
os.rename(paths.get() + "/" + file, paths.get() + "/" + new_name)
print("Job Complete")
submit = Button(root, text = "Run", command =lambda: run())
submit.grid(row = 9, column =2)
root.mainloop()
"
Thats my entire program
Try to filter out the files which are not identified as images by PIL. Something like this might work for you
def image_filter(filename):
file_path = os.path.join(paths.get(), filename)
try:
im = PIL.Image.open(file_path)
im.verify()
im.close()
return True
except: # you can handle PIL.UnidentifiedImageError here
return False
def add():
...
files = os.listdir(path)
# filter out the files which are not images
files = list(filter(image_filter, files))
files.sort()
image1 = files[0]
...

tkinter multiple radio buttons

I have 2 sets of radio buttons to be selected, if I select one of the second set, the selected button in the first set will be de-selected, although the related function is still working.
Here is the example and code
For “Need Specific Number?” (radio 1 and radio 2) and “Want to Send email with different email address?”(radio 5 and radio 6), I can only select 1 of them. for example, if I select radio 1, then select radio 5 or radio 6, radio 1 is de-selected. I am not sure where I did wrong.
Could you kindly point out the correct way?
Here is my code
from tkinter import *
from tkinter import messagebox
from tkinter.ttk import *
root = Tk()
def guiUDP():
def enableSPNum() :
entry5.configure(state = 'normal')
def disableSPNum() :
entry5.configure(state = 'disabled')
def diffEmail() :
entry8.configure(state = 'normal')
def defaultEmail() :
entry8.configure(state = 'disabled')
def submitReq() :
userID = entry1.get()
siteCode = entry2.get().upper()
firstName = entry3.get().title()
lastName = entry4.get().upper()
spNum = entry5.get()
vmEnable = select1.get()
agentID = entry7.get().lower()
eMail = entry8.get()
entry1 = Entry(root)
entry1.grid(column = 1, row = 0)
label1 = Label(root, text = 'userID : ')
label1.grid(column = 0, row = 0, sticky = E)
entry2 = Entry(root)
entry2.grid(column = 1, row = 1)
label2 = Label(root, text = 'Site Code :')
label2.grid(column = 0, row = 1, sticky = E)
entry3 = Entry(root)
entry3.grid(column = 1, row = 2)
label3 = Label(root, text = 'First Name :')
label3.grid(column = 0, row = 2, sticky = E)
entry4 = Entry(root)
entry4.grid(column = 1, row = 3)
label4 = Label(root, text = 'Last Name :')
label4.grid(column = 0, row = 3, sticky = E)
#selected = IntVar()
label5 = Label(root, text = 'Need Specific Number? :')
label5.grid(column = 0, row = 4, sticky = E)
rad1 = Radiobutton(root,text='Yes', value = 1, command = enableSPNum)
rad2 = Radiobutton(root,text='No (Default)', value = 2, command = disableSPNum)
rad1.grid(column = 1, row = 4)
rad2.grid(column = 2, row = 4)
entry5 = Entry(root, state = 'disabled')
entry5.grid(column = 1, row = 6)
label6 = Label(root, text = 'Extension :')
label6.grid(column = 0, row = 6, sticky = E)
label7 = Label(root, text = 'Voicemail Required? :')
label7.grid(column = 0, row = 7, sticky = E)
select1 = IntVar()
rad3 = Radiobutton(root,text='Yes', value = 3, variable = select1)
rad4 = Radiobutton(root,text='No', value = 4, variable=select1)
rad3.grid(column = 1, row = 7)
rad4.grid(column = 2, row = 7)
entry7 = Entry(root)
entry7.grid(column = 1, row = 8)
label8 = Label(root, text = 'Your userID :')
label8.grid(column = 0, row = 8, sticky = E)
label9 = Label(root, text = 'Want to send email with differnt email adrress? :')
label9.grid(column = 0, row = 9, sticky = E)
#selected = IntVar()
rad5 = Radiobutton(root,text='Yes', value = 5, command = diffEmail)
rad6 = Radiobutton(root,text='No', value = 6, command = defaultEmail)
rad5.grid(column = 1, row = 9)
rad6.grid(column = 2, row = 9)
entry8 = Entry(root, state = 'disabled')
entry8.grid(column = 1, row = 10)
label10 = Label(root, text = 'Full Email Address :')
label10.grid(column = 0, row = 10, sticky = E)
btn = Button(root, text = 'Submit', command = submitReq)
btn.grid(column = 2, row = 20)
mainMenu = Menu(root)
root.configure(menu=mainMenu)
guiMenu = Menu(mainMenu, tearoff = 0)
mainMenu.add_cascade(label = 'TEST', menu=guiMenu)
guiMenu.add_command(label = 'TEST', command = guiUDP)
root.mainloop()
root.geometry('600x600')
You have not assigned a variable to the first and third row of radiobuttons. If I interrogate the radiobuttons without a variable they say they are bound to selectedButton, which is the same for all of them. I'm guessing this is some kind of default behaviour when variable is missing. If you create a variable for each of the rows of associated radiobuttons and assign it to them, the effect goes away.

Resources