Hi,
I wrote a small app which have some different pages but now i have a problem with update dynamically a label text from one of the pages.
I would highly appreciate if anyone can have a look and maybe help me...
I want to update self.label1 from pag01 class text with variable ain0 value .
this is the code
import Tkinter
import tkMessageBox
from Tkinter import *
import MySQLdb
import sys
import datetime
from datetime import timedelta
import time
import calendar
import u3
import struct
import traceback
import uuid
d = u3.U3()
d.configU3()
d.getCalibrationData()
d.configIO(FIOAnalog = 255)
d.configIO(EIOAnalog=12)
d.configIO(NumberOfTimersEnabled = 2,TimerCounterPinOffset = 8)
t0Config = u3.TimerConfig(0, TimerMode = 2)
t1Config = u3.TimerConfig(1, TimerMode = 2)
d.getFeedback( t0Config, t1Config )
d.configTimerClock(TimerClockBase = 2, TimerClockDivisor = 48)
timer0 = u3.Timer(0)
timer1 = u3.Timer(1)
ainVoltage = [0]*8
ainVoltage[0] = d.getAIN(0, negChannel = 32)
ain0 = ainVoltage[0]
#connect to db
db = MySQLdb.connect(host="localhost",
user="***",
passwd="***",
db="***")
#create cursor
cur = db.cursor()
#set client related variables
cur.execute("SELECT * FROM users")
for row1 in cur.fetchall():
client_id = row1[1]
client_name = row1[2]
client_username = row1[3]
client_license = row1[4]
client_license_expire = row1[5]
client_last_connect_asv = row1[6]
client_password = row1[7]
#util variables
today = datetime.date.today()
today_5 = today - timedelta(days=5)
#
class Pag00():
def __init__(self,master):
self.master=master
self.master.geometry('1024x680+50+50')
self.master.title('ASV Technologies ')
self.master.configure(background='#CDC5D9')
self.label1=Label(self.master,text='Sistem testare frane ASV',fg='blue', font=("Arial", 36, "bold"),background='#CDC5D9').grid(row=0,column=2)
self.labelspatiere=Label(self.master,text='',font=("Arial", 18, "bold"),background='#CDC5D9').grid(row=1,column=2)
self.labelspatiere=Label(self.master,text=' ',font=("Arial", 18, "bold"),background='#CDC5D9').grid(row=0,column=0)
self.labelspatiere=Label(self.master,text='',font=("Arial", 18, "bold"),background='#CDC5D9').grid(row=3,column=2)
self.labelspatiere=Label(self.master,text='',font=("Arial", 18, "bold"),background='#CDC5D9').grid(row=5,column=2)
self.labelspatiere=Label(self.master,text='',font=("Arial", 18, "bold"),background='#CDC5D9').grid(row=7,column=2)
self.labelspatiere=Label(self.master,text='',font=("Arial", 18, "bold"),background='#CDC5D9').grid(row=9,column=2)
self.labelspatiere=Label(self.master,text='',font=("Arial", 18, "bold"),background='#CDC5D9').grid(row=11,column=2)
self.labelspatiere=Label(self.master,text=' ',font=("Arial", 18, "bold"),background='#CDC5D9').grid(row=1,column=4)
self.labelclienttxt=Label(self.master,text='Licensed to : ',font=("Arial", 18, "bold"),background='#CDC5D9').grid(row=2,column=5)
self.labelclientname=Label(self.master,text=client_name,font=("Arial", 18, "bold"),fg='blue',background='#CDC5D9').grid(row=3,column=5)
text_label_hardware = hardware_check(client_id)
if hardware_check(client_id) == "OK":
color_label_hardware = "#00C957"
elif hardware_check(client_id) == "Invalid hardware":
color_label_hardware = "#EE0000"
self.labelhwinittext=Label(self.master,text='Hardware status ',font=("Arial", 18, "bold"),background='#CDC5D9').grid(row=4,column=5)
self.labelhwinit=Label(self.master,text=text_label_hardware,font=("Arial", 18, "bold"),fg=color_label_hardware,background='#CDC5D9').grid(row=5,column=5)
self.labellictext=Label(self.master,text='License validity : ',font=("Arial", 18, "bold"),background='#CDC5D9').grid(row=6,column=5)
self.labellic=Label(self.master,text=client_license_expire,font=("Arial", 18, "bold"),fg='red',background='#CDC5D9').grid(row=7,column=5)
text_label_status = status_check(client_last_connect_asv)
if status_check(client_last_connect_asv) == "OK":
color_label_status = "#00C957"
elif status_check(client_last_connect_asv) == "System Problem":
color_label_status = "#EE0000"
self.labelstatustext=Label(self.master,text='System status : ',font=("Arial", 18, "bold"),background='#CDC5D9').grid(row=8,column=5)
self.labelstatus=Label(self.master,text=text_label_status,font=("Arial", 18, "bold"),fg=color_label_status,background='#CDC5D9').grid(row=9,column=5)
self.labellic2x4=Label(self.master,text='YES',font=("Arial", 18, "bold"),fg='#7CFC00',background='#CDC5D9').grid(row=2,column=3)
self.labellic4x4=Label(self.master,text='YES',font=("Arial", 18, "bold"),fg='orange',background='#CDC5D9').grid(row=4,column=3)
self.labelliccamion=Label(self.master,text='NO',font=("Arial", 18, "bold"),fg='red',background='#CDC5D9').grid(row=6,column=3)
self.labellicmoto=Label(self.master,text='YES',font=("Arial", 18, "bold"),fg='orange',background='#CDC5D9').grid(row=8,column=3)
self.button1=Button(self.master,text='Autoturism 2x4',fg='blue',font=('Helvetica',26),command=self.gotoPag01,height=1, width=15).grid(row=2,column=2)
self.button2=Button(self.master,text='Autoturism 4x4',fg='blue',font=('Helvetica',26),command=self.gotoPag02,height=1, width=15).grid(row=4,column=2)
self.button3=Button(self.master,text='Camion',fg='blue',font=('Helvetica',26),command=self.gotoPag02,height=1, width=15).grid(row=6,column=2)
self.button4=Button(self.master,text='Moto',fg='blue',font=('Helvetica',26),command=self.gotoPag02,height=1, width=15).grid(row=8,column=2)
self.button5=Button(self.master,text='Setari',fg='blue',font=('Helvetica',26),command=self.gotoPag01,height=1, width=15).grid(row=10,column=2)
self.button6=Button(self.master,text='Exit',fg='blue',font=('Helvetica',26),command=self.exit,height=1, width=15).grid(row=12,column=2)
def gotoPag01(self):
root1=Toplevel(self.master)
myGui=Pag01(root1)
def gotoPag02(self):
root2=Toplevel(self.master)
myGui=Pag02(root2)
def gotoPag03(self):
root3=Toplevel(self.master)
myGui=Pag03(root3)
def gotoPag04(self):
root4=Toplevel(self.master)
myGui=Pag04(root4)
def gotoPag05(self):
root5=Toplevel(self.master)
myGui=Pag05(root5)
def exit(self):
mExit = tkMessageBox.askyesno(title='Exit', message='Are you sure ?')
if mExit > 0:
self.master.destroy()
return
class Pag01():
def __init__(self,master):
self.master=master
self.master.geometry('1024x680+50+50')
self.master.title('ASV Technologies - Test frane auto 2x4')
#Here i want my ain0 value
self.label1=Label(self.master,text=ain0,fg='red').grid(row=0,column=2)
self.button2=Button(self.master,text='back',fg='blue',command=self.myquit).grid(row=5,column=3)
def myquit(self):
self.master.destroy()
#pag02()
#etc...
#pag05()
def main():
root=Tk()
myGuiPag00=Pag00(root)
root.mainloop()
if __name__ == '__main__':
main()
Thanks a lot in advance