i dont know why i cannot put all of my code
i created a function w3 and i add some checkbuttons the problem is that if the user clicks "< Υποβολή >" the function listokouti only recognizes the messagebox and its like i never put elif,can anyone help?
i1=IntVar()
i2=IntVar()
i3=IntVar()
i4=IntVar()
i5=IntVar()
#i6=IntVar()
#i7=IntVar()
# checkbuttons
check1 = tk.Checkbutton(rain,text="Τίτλος",font=('',13),variable=i1,onvalue=1,offvalue=0).pack(expand=1,anchor="nw")
check2 = tk.Checkbutton(rain,text="Tίτλος(Μετάφραση)",font=('',13),variable=i2,onvalue=1,offvalue=0).pack(expand=1,anchor="nw")
check3 = tk.Checkbutton(rain,text="Συγγραφέας",font=('',13),variable=i3,onvalue=1,offvalue=0).pack(expand=1,anchor="nw")
check4 = tk.Checkbutton(rain,text="Λέξεις κλειδιά",font=('',13),variable=i4,onvalue=1,offvalue=0).pack(expand=1,anchor="nw")
check5 = tk.Checkbutton(rain,text="Λέξεις κλειδιά(Μετάφραση)",font=('',13),variable=i5,onvalue=1,offvalue=0).pack(expand=1,anchor="nw")
def listokouti():
if i1.get()==0 and i2.get()==0 and i3.get()==0 and i4.get()==0 and i5.get()==0 :
vsause=messagebox.showwarning("team.33","Παρακαλώ επιλέξτε φίλτρα")
elif i1.get()==1 or i2.get()==1 or i3.get()==1 or i4.get()==1 or i5.get()==1 :
money=tk.Tk()
money.title("team.33")
money.iconbitmap('C:\Program Files (x86)\icon.ico')
# money.config(bg="#000000")
frame=tk.Frame(money)
scrollarw1=ttk.Scrollbar(frame,orient=VERTICAL)
my_listbox= tk.Listbox(frame,yscrollcommand=scrollarw1.set,width=50)
scrollarw1.config(command=my_listbox.yview)
scrollarw1.pack(side=RIGHT,fill= Y)
scrollarw2=ttk.Scrollbar(frame,orient=HORIZONTAL)
scrollarw2.config(command=my_listbox.xview)
scrollarw2.pack(side=BOTTOM,fill= X)
frame.pack()
my_listbox.pack(pady=20)
# to item einai akyro to evala mono gia na leitoyrgei to scrollbar
for item in range(1,101):
my_listbox.insert(END,item)
butt =tk.Button(money,text="< Υποβολή >",font=("",10,'bold'),command=ergasia).pack()
money.mainloop()
b1 = tk.Button(rain,text="< Υποβολή >",font=("",10,"bold"),command= listokouti).pack(expand=1)
rain.mainloop()
w3()
Related
This so weird, like i am trying to use if statement and the selection in combobox to do some specific command and when combobox value is selected to 'full_name' (part of elif) they return an messagebox, that is supposed to be showed only when the first if statement is executed but according to the conditions its supposed to return the elif part but it returns the if part. Is there a mistake in my code? If the Q is unclear please try referring the code or lemme knw :) Thanks in advance.
CODE:
def sp_patient():
#Creating window
sp_pat = Toplevel(update)
sp_pat.title('Choose Patient')
def search():
#Assigning variable to .get()
a = drops.get()
if a == 'id' or 'emirate_id' or 'email_adress' or 'gender' or 'DOB' or 'blood_grp' or 'COVID_test':
#Establishing connection
con = mysql.connect(host='***', user='nihaalnz',
password='****', database='nihaalnztrying')
# Making SQL command
c = con.cursor()
c.execute(f"SELECT * FROM patient_infos where `{a}` = '{e_1.get()}'")
# Executing and saving SQL command
records = c.fetchall()
if records == []:
messagebox.showinfo('Does not exist!','Sorry such patient does not exist')
else:
#Creating window
result_win = Toplevel(sp_pat)
result_win.title('Search result')
index=0
for index,x in enumerate(records):
num=0
for y in x:
lookup_label = Label(result_win,text=y)
lookup_label.grid(row=index+1,column=num)
num += 1
#Closing connection
con.close()
#Creating column header and exit button
l_1 = Label(result_win,text='ID',font=font_text)
l_2 = Label(result_win,text='Full Name',font=font_text)
l_3 = Label(result_win,text='Phone no.',font=font_text)
l_4 = Label(result_win,text='Emirates ID',font=font_text)
l_5 = Label(result_win,text='Email addr.',font=font_text)
l_6 = Label(result_win,text='Gender',font=font_text)
l_7 = Label(result_win,text='DOB',font=font_text)
l_8 = Label(result_win,text='Nationality',font=font_text)
l_9 = Label(result_win,text='Blood group',font=font_text)
l_10 = Label(result_win,text='COVID test',font=font_text)
l_11 = Label(result_win,text='Emergency no.',font=font_text)
btn_ext = Button(result_win,text='Exit',font=font_text,command=result_win.destroy,borderwidth=2,fg='#eb4d4b')
#Placing it in screen
l_1.grid(row=0,column=0,padx=20)
l_2.grid(row=0,column=1,padx=20)
l_3.grid(row=0,column=2,padx=20)
l_4.grid(row=0,column=3,padx=20)
l_5.grid(row=0,column=4,padx=20)
l_6.grid(row=0,column=5,padx=20)
l_7.grid(row=0,column=6,padx=20)
l_8.grid(row=0,column=7,padx=20)
l_9.grid(row=0,column=8,padx=20)
l_10.grid(row=0,column=9,padx=20)
l_11.grid(row=0,column=10,padx=20)
btn_ext.grid(row=index+2,columnspan=11,ipadx=240,sticky=E+W)
elif a == 'full_name' or 'ph_no' or 'nationality' or 'emergency_no':
#Creating window
result_win = Toplevel(sp_pat)
result_win.title('Search result')
#Establishing connection
con = mysql.connect(host='****', user='nihaalnz',
password='*****', database='nihaalnztrying')
# Making SQL command
c = con.cursor()
c.execute(f"SELECT * FROM patient_infos where `{a}` regexp '{e_1.get()}'")
# Executing and saving SQL command
records = c.fetchall()
index=0
for index,x in enumerate(records):
num=0
for y in x:
lookup_label = Label(result_win,text=y)
lookup_label.grid(row=index+1,column=num)
num += 1
#Closing connection
con.close()
#Creating column headers and exit button
l_1 = Label(result_win,text='ID',font=font_text)
l_2 = Label(result_win,text='Full Name',font=font_text)
l_3 = Label(result_win,text='Phone no.',font=font_text)
l_4 = Label(result_win,text='Emirates ID',font=font_text)
l_5 = Label(result_win,text='Email addr.',font=font_text)
l_6 = Label(result_win,text='Gender',font=font_text)
l_7 = Label(result_win,text='DOB',font=font_text)
l_8 = Label(result_win,text='Nationality',font=font_text)
l_9 = Label(result_win,text='Blood group',font=font_text)
l_10 = Label(result_win,text='COVID test',font=font_text)
l_11 = Label(result_win,text='Emergency no.',font=font_text)
btn_ext = Button(result_win,text='Exit',font=font_text,command=result_win.destroy,borderwidth=2,fg='#eb4d4b')
#Placing it on screen
l_1.grid(row=0,column=0,padx=20)
l_2.grid(row=0,column=1,padx=20)
l_3.grid(row=0,column=2,padx=20)
l_4.grid(row=0,column=3,padx=20)
l_5.grid(row=0,column=4,padx=20)
l_6.grid(row=0,column=5,padx=20)
l_7.grid(row=0,column=6,padx=20)
l_8.grid(row=0,column=7,padx=20)
l_9.grid(row=0,column=8,padx=20)
l_10.grid(row=0,column=9,padx=20)
l_11.grid(row=0,column=10,padx=20)
btn_ext.grid(row=index+2,columnspan=11,ipadx=240,sticky=E+W)
elif a == 'Search by...':
#Error message
messagebox.showinfo('No choice given','Please choose a valid option to search by...')
#Defining dropdown and entry box
drops = ttk.Combobox(sp_pat,value=['Search by...','id','full_name','ph_no','emirate_id','email_addr','gender','DOB','nationality','blood_grp','COVID_test','emergency_no'],state='readonly')
print(drops.get())
drops.current(0)
e_1 = Entry(sp_pat)
#Defining Labels and search button
l_sch = Label(sp_pat,text='Search',font=Font(size='20'))
l_id = Label(sp_pat,text='Enter',font=font_text)
bt_db = Button(sp_pat,text='Search',command=search)
#Placing it in screen
drops.grid(row=1,columnspan=3,ipady=5,padx=5,pady=10)
e_1.grid(row=2,column=1,ipady=5,padx=5,pady=5)
l_id.grid(row=2,column=0,padx=5,pady=5)
bt_db.grid(row=3,columnspan=2,padx=5,pady=5,sticky=E+W)
l_sch.grid(row=0,columnspan=2,sticky=E+W,padx=10,pady=10)
The problem is this line:
if a == 'id' or 'emirate_id' or...
This statement always return True. It is evaluating whether a=="id" or emirate_id is True, and a non-empty string always returns True.
You can be explicit and use:
if a == 'id' or a == 'emirate_id' or ...
Or better yet, use keyword in:
if a in ("id", "emirate_id",...)
I am trying to save a document based on a if statement.
Here I am creating radiobuttons:
info = ["Option 1", "Option 2", "Option 3"]
vars = []
for idx,i in enumerate(info):
var = IntVar(value=0)
vars.append(var)
lblOption = Label(main,text=i)
btnYes = Radiobutton(main, text="Yes", variable=var, value=2)
btnNo = Radiobutton(main, text="No", variable=var, value=1)
btnNa = Radiobutton(main, text="N/A", variable=var,value=0)
lblOption.grid(column=4,row=idx, sticky = W)
btnYes.grid(column=1,row=idx)
btnNo.grid(column=2,row=idx)
btnNa.grid(column=3,row=idx)
Here I am creating a document
document = Document()
#add table
table = document.add_table(1, 4)
#style table
table.style = 'Table Grid'
#populate header row
heading_cells = table.rows[0].cells
heading_cells[0].text = "Options"
heading_cells[1].text = "Yes"
heading_cells[2].text = "No"
heading_cells[3].text = "N/a"
for idx, item in enumerate(vars):
cells = table.add_row().cells
cells[0].text = info[idx] # gets the option name
val = item.get() #radiobutton value
if val == 2: # checks if yes
cells[1].text = "*"
elif val == 1: # checks if no
cells[2].text = "*"
elif val == 0: # checks if N/A
cells[3].text = "*"
#save doc
document.save("test.docx")
Work behind the scenes:
Out of the 3 radio-button Yes, No, N/a.. Only one can be chosen.
Next, when pressed a button save.. it creates a table in docx, Options is in row 0 appending down along with selected values of Yes, no & N/a.
As an example:
Options Yes No N/a
Option 1 *
Option 2 *
Option 3 *
My Problem:
I can simply press save and it saves the file as test.docx.
Now, I am trying to figure out how to save the file as Failed.docx
The Failed.docx will only be created if one or more out of all the options has a no value selected.
As an example below, this would be saved as Test.docx, because not a single Option has a no value selected:
Options Yes No N/a
Option 1 *
Option 2 *
Option 3 *
An example below, this would be saved as Failed.docx, because no option has been selected for one of the options on the left.
As an example:
Options Yes No N/a
Option 1 *
Option 2 *
Option 3 *
Here is what I have tried so far:
for x in cells[2].text:
if "*" in x:
print("True")
else:
print("False")
This detects * within the cell[2] (This is row 2 linked to No value).
And if a 'no' value has been selected it prints out true but also prints out false
As an example:
Options Yes No N/a
Option 1 *
Option 2 *
Option 3 *
Output of the for loop :
False
True
False
But if it detects False and True both files will be saved. I am totally confused where to go from here..
Question: The 'Failed.docx' will only be created if one or more out of all the options has a no value selected.
This can be rephrased to:
if any option has NO
You have build a list of Boolean from the condition value == NO,
like [False, True, False]
Built-in - any
any(iterable)
Return True if any element of the iterable is true. If the iterable is empty, return False.
YES = 2; NO = 1; NA = 0
print(vars)
if any([v.get() == NO for v in vars]):
print('Failed.docx')
else:
print('test.docx')
Output:
[2, 0, 2]
test.docx
[2, 1, 2]
Failed.docx
Try the following:
for x in cells[2].text:
if "*" in x:
print("Failed.docx")
elif "*" not in x:
print("Test.docx")
this checks if any "*" is inside your no row, if it exists save as Failed.docx if not save as Test.docx
The application should search one of the column in an excel and and display corresponding column as a result but i am not able to get the values. I think i am not able to map the dictionary to the display tab using tkinter. Please help.
Below file is in outlook
Search (Input) Result (Output)
1 a
2 b
3 c
4 d
from tkinter import *
import tkinter.messagebox
import pandas as pd
root=Tk()
root.geometry('450x550')
root.title("Welcome")
root.configure(background="silver")
#Entry widget object
textin=StringVar()
**exlist = pd.read_excel('foo6.xls', index_col=0).to_dict('index')**
def clk():
entered = ent.get()
output.delete(0.0,END)
try:
textin = exlist[entered]
except:
textin = 'SORRY NO INFO \n AVAILABLE!!!!!!!!\n'
output.insert(0.0,textin)
def ex():
tkinter.messagebox.showinfo("Program",'Exit')
exit()
def exitt():
tkinter.messagebox.showinfo("Program",'Exit')
exit()
def me():
text='\n XYZ \n Piyushrkc \n Nice'
saveFile=open('text.txt','w')
saveFile.write(text)
print('This are the entries::',text)
def hel():
help(tkinter)
def cont():
tkinter.messagebox.showinfo("S/W Contributors",'\n Piyush ___Version 1.0___')
def clr():
textin.set(" ")
menu = Menu(root)
root.config(menu=menu)
subm = Menu(menu)
menu.add_cascade(label="File",menu=subm)
subm.add_command(label="Memo",command=me)
subm.add_command(label="Save")
subm.add_command(label="Save As")
subm.add_command(label="Print")
subm.add_command(label="Exit",command=ex)
subm1 = Menu(menu)
menu.add_cascade(label="Tools",menu=subm1)
subm1.add_command(label="Tkinter Help",command=hel)
subm2 = Menu(menu)
menu.add_cascade(label="About",menu=subm2)
subm2.add_command(label="Contributors",command=cont)
lab=Label(root,text='Name :',font=('none 20 bold'))
lab.grid(row=0,column=1,sticky=W)
ent=Entry(root,width=20,font=('none 18 bold'),textvar=textin,bg='white')
ent.grid(row=0,column=2,sticky=W)
but=Button(root,padx=2,pady=2,text='Submit',command=clk,bg='powder blue',font=('none 18 bold'))
but.place(x=100,y=90)
but4=Button(root,padx=2,pady=2,text='Clear',font=('none 18 bold'),bg='powder blue',command=clr)
but4.place(x=220,y=90)
output=Text(root,width=20,height=8,font=('Time 20 bold'),fg="black")
output.place(x=100,y=200)
labb=Label(root,text='Results',font=('non 18 bold'))
labb.place(x=0,y=180)
but1=Button(root,padx=2,pady=2,text='Exit',command=exitt,bg='powder blue',font=('none 18 bold'))
but1.place(x=200,y=470)
root.mainloop()
I have 3 radiobutton groups in forms of Yes or No. I want to disable the last 2 radiobutton groups if the first radiobutton is "No" and enable them when the first radiobutton is "Yes". I can make the enabled or disabled by default but toggling Yes/No from the first group doesn't change the result in the second and third group.
Here is a summary of my code:
self.yes_radioButtonGroup1 = QtGui.QRadioButton(self.centralwidget)
self.yes_radioButtonGroup1.setObjectName(_fromUtf8("yes_radioButtonGroup1"))
self.no_radioButtonGroup1 = QtGui.QRadioButton(self.centralwidget)
self.no_radioButtonGroup1.setObjectName(_fromUtf8("no_radioButtonGroup1"))
self.radioButtonGroup1= QtGui.QButtonGroup(MainWindow)
self.radioButtonGroup1.setObjectName(_fromUtf8("radioButtonGroup1"))
self.radioButtonGroup1.addButton(self.yes_radioButtonGroup1)
self.radioButtonGroup1.addButton(self.no_radioButtonGroup1)
self.yes_radioButtonGroup2 = QtGui.QRadioButton(self.centralwidget)
self.yes_radioButtonGroup2.setObjectName(_fromUtf8("yes_radioButtonGroup2"))
self.no_radioButtonGroup2 = QtGui.QRadioButton(self.centralwidget)
self.no_radioButtonGroup2.setObjectName(_fromUtf8("no_radioButtonGroup2"))
self.radioButtonGroup2= QtGui.QButtonGroup(MainWindow)
self.radioButtonGroup2.setObjectName(_fromUtf8("radioButtonGroup2"))
self.radioButtonGroup2.addButton(self.yes_radioButtonGroup1)
self.radioButtonGroup2.addButton(self.no_radioButtonGroup1)
self.yes_radioButtonGroup3 = QtGui.QRadioButton(self.centralwidget)
self.yes_radioButtonGroup3.setObjectName(_fromUtf8("yes_radioButtonGroup3"))
self.no_radioButtonGroup3 = QtGui.QRadioButton(self.centralwidget)
self.no_radioButtonGroup3.setObjectName(_fromUtf8("no_radioButtonGroup3"))
self.radioButtonGroup3= QtGui.QButtonGroup(MainWindow)
self.radioButtonGroup3.setObjectName(_fromUtf8("radioButtonGroup3"))
self.radioButtonGroup3.addButton(self.yes_radioButtonGroup3)
self.radioButtonGroup3.addButton(self.no_radioButtonGroup3)
if self.yes_radioButtonGroup1.isChecked() == True:
self.yes_radioButtonGroup2.setEnabled(True)
self.no_radioButtonGroup2.setEnabled(True)
self.yes_radioButtonGroup3.setEnabled(True)
self.no_radioButtonGroup3.setEnabled(True)
elif self.no_radioButtonGroup1.isChecked() == True:
self.yes_radioButtonGroup2.setEnabled(False)
self.no_radioButtonGroup2.setEnabled(False)
self.yes_radioButtonGroup3.setEnabled(False)
self.no_radioButtonGroup3.setEnabled(False)
I was wondering if anybody knows how to dynamically enable or disable the last two radiobutton group when values from the first radiobutton changes?
Since the buttons are exclusive enough to monitor one of them, so the appropriate signal is toggled() that sends the information if the button is checked or not.
self.yes_radioButtonGroup1 = QtGui.QRadioButton(self.centralwidget)
self.yes_radioButtonGroup1.setObjectName(_fromUtf8("yes_radioButtonGroup1"))
self.no_radioButtonGroup1 = QtGui.QRadioButton(self.centralwidget)
self.no_radioButtonGroup1.setObjectName(_fromUtf8("no_radioButtonGroup1"))
self.radioButtonGroup1= QtGui.QButtonGroup(MainWindow)
self.radioButtonGroup1.setObjectName(_fromUtf8("radioButtonGroup1"))
self.radioButtonGroup1.addButton(self.yes_radioButtonGroup1)
self.radioButtonGroup1.addButton(self.no_radioButtonGroup1)
self.yes_radioButtonGroup2 = QtGui.QRadioButton(self.centralwidget)
self.yes_radioButtonGroup2.setObjectName(_fromUtf8("yes_radioButtonGroup2"))
self.no_radioButtonGroup2 = QtGui.QRadioButton(self.centralwidget)
self.no_radioButtonGroup2.setObjectName(_fromUtf8("no_radioButtonGroup2"))
self.radioButtonGroup2= QtGui.QButtonGroup(MainWindow)
self.radioButtonGroup2.setObjectName(_fromUtf8("radioButtonGroup2"))
self.radioButtonGroup2.addButton(self.yes_radioButtonGroup1)
self.radioButtonGroup2.addButton(self.no_radioButtonGroup1)
self.yes_radioButtonGroup3 = QtGui.QRadioButton(self.centralwidget)
self.yes_radioButtonGroup3.setObjectName(_fromUtf8("yes_radioButtonGroup3"))
self.no_radioButtonGroup3 = QtGui.QRadioButton(self.centralwidget)
self.no_radioButtonGroup3.setObjectName(_fromUtf8("no_radioButtonGroup3"))
self.radioButtonGroup3= QtGui.QButtonGroup(MainWindow)
self.radioButtonGroup3.setObjectName(_fromUtf8("radioButtonGroup3"))
self.radioButtonGroup3.addButton(self.yes_radioButtonGroup3)
self.radioButtonGroup3.addButton(self.no_radioButtonGroup3)
self.yes_radioButtonGroup1.toggled(self.on_yes_checked)
# set initial state
self.on_yes_checked(self.yes_radioButtonGroup1.isChecked())
def on_yes_checked(self, checked):
self.yes_radioButtonGroup2.setEnabled(checked)
self.no_radioButtonGroup2.setEnabled(checked)
self.yes_radioButtonGroup3.setEnabled(checked)
self.no_radioButtonGroup3.setEnabled(checked)
I have Tkinter program that has to add a significant amount of data to the window so I tried to write a for loop to take care of it but since I have to use a string variable for the name of the object that Tkinter is running .insert() on the object. I didn't explain it very well here is the method
def fillWindow(self):
global fileDirectory
location = os.path.join(fileDirectory, family + '.txt')
file = open(location, 'r')
ordersDict = {}
for line in file:
(key, value) = line.split(':', 1)
ordersDict[key] = value
for key in ordersDict:
ordersDict[key] = ordersDict[key][:-2]
for item in ordersDict:
if item[0] == '#':
if item[1] == 'o':
name = 'ordered%s' %item[2:]
right here is the problem line because I have the variable that matches the name of the entry object already created but 'name' is actually a string variable so it gives me the error "AttributeError: 'str' object has no attribute 'insert'"
name.insert(0,ordersDict[item])
here is the entire class. It makes a Tkinter window and fills it with a sort of shipping screen so all the entries are for how many orders of a certain thing are needed. I'm also very new so I know that I do things the long way a lot.
class EditShippingWindow(Tkinter.Toplevel):
def __init__(self, student):
Tkinter.Toplevel.__init__(self)
self.title('Orders')
family = student
## Window Filling
ageGroupLabel = Tkinter.Label(self,text='Age Group')
ageGroupLabel.grid(row=0,column=0)
itemColumnLabel = Tkinter.Label(self,text='Item')
itemColumnLabel.grid(row=0, column=1)
costColumnLabel = Tkinter.Label(self,text='Cost')
costColumnLabel.grid(row=0, column=2)
orderedColumnLabel = Tkinter.Label(self,text='Ordered')
orderedColumnLabel.grid(row=0, column=3)
paidColumnLabel = Tkinter.Label(self,text='Paid')
paidColumnLabel.grid(row=0, column=4)
receivedColumnLabel = Tkinter.Label(self,text='Received')
receivedColumnLabel.grid(row=0, column=5)
#Item Filling
column1list = ['T-Shirt (2T):$9.00', 'T-Shirt (3T):$9.00', 'T-Shirt (4T):$9.00',
'Praise Music CD:$10.00', ':', 'Vest L(Size 6):$10.00', 'Vest XL(Size 8):$10.00',
'Hand Book (KJ/NIV):$8.75', 'Handbook Bag:$6.00', 'Memory CD (KJ/NIV):$10.00',
':', 'Vest L(size 10):$10.00', 'Vest XL(Size 12):$10.00', 'Hand Glider (KJ/NIV/NKJ):$10.00',
'Wing Runner (KJ/NIV/NKJ):$10.00', 'Sky Stormer (KJ/NIV/NKJ):$10.00', 'Handbook Bag:$5.00',
'Memory CD (S/H/C):$10.00', 'Hand Glider Freq. Flyer:$8.00', 'Wing Runner Freq. Flyer:$8.00',
'Sky Stormer Handbook:$8.00' , ':', 'Uniform T-Shirt Size (10/12/14):$13.00',
'Uniform T-Shirt Size(10/12/14):$13.00', 'Uniform T-Shirt(Adult S / M / L / XL):$13.00',
'3rd & 4th Gr. Book 1 (KJ / NIV / NKJ):$8.75', '3rd & 4th Gr. Book 2 (KJ / NIV / NKJ):$8.75',
'4th & 5th Gr. Book 1 (KJ / NIV / NKJ):$8.75', '4th & 5th Gr. Book 2 (KJ / NIV / NKJ):$8.75',
'Memory CD 3rd & 4th Gr. Book (1/2):$10.00', 'Drawstring Backpack:$5.50']
column1num = 1
for item in column1list:
num = str(column1num)
(title, price) = item.split(':')
objectName1 = 'column1row' + num
objectName1 = Tkinter.Label(self,text=title)
objectName1.grid(row=column1num, column=1)
objectName2 = 'column1row' + num
objectName2 = Tkinter.Label(self,text=price)
objectName2.grid(row=column1num, column=2)
column1num += 1
#Ordered Paid Recieved Filler
for i in range(32):
if i == 11 or i == 22 or i == 0 or i == 5:
pass
else:
width = 10
# First Column
title1 = 'ordered' + str(i)
self.title1 = Tkinter.Entry(self,width=width)
self.title1.grid(row=i,column=3)
#self.title1.insert(0, title1)
#Second
title2 = 'paid' + str(i)
self.title2 = Tkinter.Entry(self,width=width)
self.title2.grid(row=i,column=4)
#self.title2.insert(0, title2)
#Third
title3 = 'received' + str(i)
self.title3 = Tkinter.Entry(self,width=width)
self.title3.grid(row=i,column=5)
#self.title3.insert(0, title3)
## Methods
def fillWindow(self):
global fileDirectory
location = os.path.join(fileDirectory, family + '.txt')
file = open(location, 'r')
ordersDict = {}
for line in file:
(key, value) = line.split(':', 1)
ordersDict[key] = value
for key in ordersDict:
ordersDict[key] = ordersDict[key][:-2]
for item in ordersDict:
if item[0] == '#':
if item[1] == 'o':
self.name = 'ordered%s' %item[2:]
self.name.insert(0,ordersDict[item])
fillWindow(self)
It looks like you have a conceptual error there: inside this method, the variable "name" does not exist up to the last line on the first listing. Then it is created, and points to an ordinary Python string -- if you are using a "name" variable elsewhere on your class that variable does not exist inside this method.
For an easy fix of your existing code, try calling the variable as "self.name" instead of just name where it is created, and on your last line in this method use:
self.name.insert(0,ordersDict[item]) instead.
The self. prefix will turn your variable into an instance variable, which is shared across methods on the same instance of the class.
On a side note, you don' t need even the dictionary much less three consecutive for loops on this method, just insert the relevant values you extract from "line" in your text variable.