Python Forum
[Tkinter] Anyone know what happened to my button?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Anyone know what happened to my button?
#1
Exclamation 
Hello good afternoon I am making an interface that can show the data of the xbee connected via usb.

I followed several videos that I have seen on informational pills, which have helped me get here.

But I have come to a problem, which I have not been able to get out.

I want to make a button that when I strip it, it sends a message to all the xbes of the network (that if it does) and this signal will start the reception of data. What I mean is that after removing the button, I will also start receiving data from the xbees.



I want to present this data on screen.

That is why I call a function and that function will give me the voltage date and time data, they are all strings and all those I indicate as StringVar (). And then I print it on some labels.



THE PROBLEM:

The button does not appear to me and the data is not printed on the labels.

You should mention that the button does appear to me if I "tie it to the root" but I did a FRAME to put all the labels there and I wanted to put the button there and it did not appear.


#-----------------------------Se importan las librerias------------------------------

from tkinter import*
from digi.xbee.devices import XBeeDevice

#-----------------------------Se inicializan Variables y puertos-----------------

PORT = "COM5"
BAUD_RATE = 9600
device = XBeeDevice(PORT, BAUD_RATE)


            
#-----------------------------Se crea la pantalla principal--------------------

raiz=Tk()
raiz.title("Sistema de Monitoreo de Paneles Solares del SESLab")
raiz.config(bg="#032539")

width_of_window = 600
height_of_window = 280

screen_width = raiz.winfo_screenwidth()
screen_height = raiz.winfo_screenheight()

x_coordinate = (screen_width/2)-(width_of_window/2)
y_coordinate = (screen_height/2)-(height_of_window/2)

raiz.geometry("%dx%d+%d+%d" % (width_of_window, height_of_window, x_coordinate, y_coordinate ))

miframe=Frame(raiz,width="1200",height="600" )
miframe.pack()
miframe.config(bg="#1C768F")

#-----------------------------Valores por Mostrar en la Pantallas-----------------

voltage=StringVar()
hora=StringVar()
fecha=StringVar()


#------------------------------Cuadros donde se muestran datos-----------------------

cuadroVisual1=Label(miframe, textvariable=fecha, fg="black",justify="center", relief ="ridge", width=20)
cuadroVisual1.pack()
cuadroVisual1.grid(row=1, column= 1, padx= 2, pady=5)

cuadroVisual2=Label(miframe, textvariable=fecha, fg="black",justify="center", relief ="ridge", width=20)
cuadroVisual2.grid(row=2, column= 1, padx= 2, pady=5)

cuadroVisual3=Label(miframe, textvariable=fecha, fg="black",justify="center", relief ="ridge", width=20)
cuadroVisual3.grid(row=4, column= 1, padx= 2, pady=5)

cuadroVisual4=Label(miframe, textvariable=fecha, fg="black",justify="center", relief ="ridge", width=20)
cuadroVisual4.grid(row=5, column= 1, padx= 2, pady=5)

cuadroVisual5=Label(miframe, textvariable=fecha, fg="black",justify="center", relief ="ridge", width=20)
cuadroVisual5.grid(row=6, column= 1, padx= 2, pady=5)

cuadroVisual6=Label(miframe, textvariable=fecha, fg="black",justify="center", relief ="ridge", width=20)
cuadroVisual6.grid(row=7, column= 1, padx= 2, pady=5)

cuadroVisual7=Label(miframe, textvariable=fecha, fg="black",justify="center", relief ="ridge", width=20, anchor= CENTER)
cuadroVisual7.grid(row=9, column= 1, padx= 2, pady=5)


#---------------------------Cuadros donde esta el Texto------------------------

miLabel1=Label(miframe, text="Sistema de monitoreo de Paneles del SESLab", font=18)
miLabel1.grid(row=0, column= 0, padx= 5, pady=5, columnspan= 2)

nombrePanel2=Label(miframe, text="Fecha de medición : ", relief ="raised")
nombrePanel2.grid(row=1, column= 0, padx= 2, pady=5)

nombrePanel3=Label(miframe, text="Hora de medición : ", relief ="raised")
nombrePanel3.grid(row=2, column= 0, padx= 2, pady=5)

nombrePanel4=Label(miframe, text="Voltage de Panel 1 : ", relief ="raised")
nombrePanel4.grid(row=4, column= 0, padx= 2, pady=5)

nombrePanel5=Label(miframe, text="Voltage de Panel 2 : ", relief ="raised")
nombrePanel5.grid(row=5, column= 0, padx= 2, pady=5)

nombrePanel6=Label(miframe, text="Voltage de Panel 3 : ", relief ="raised")
nombrePanel6.grid(row=6, column= 0, padx= 2, pady=5)

nombrePanel7=Label(miframe, text="Promedio : ", relief ="raised")
nombrePanel7.grid(row=7, column= 0, padx= 2, pady=5)

nombrePanel8=Label(miframe, text="Panel con Menor Voltaje : ", relief ="raised")
nombrePanel8.grid(row=9, column= 0, padx= 2, pady=5)

#------------------------Función que manda un mensaje Broadcast a Xbees---------
#------------------------Mensaje recibido----------------------------------------

def codigoIniciar():
    device.open()
    DATA_TO_SEND = "Hola XBee!"
    device.send_data_broadcast(DATA_TO_SEND)
    
    try: 
        device.flush_queues()
        while True:
            xbee_message = device.read_data()
            if xbee_message is not None:
                ##direccion.set(xbee_message.remote_device.get_64bit_addr()) 
                data = xbee_message.data.decode()
                voltage.set(data.split(",")[0])
                hora.set(data.split(",")[1])
                #fecha.set(data.split(",")[2])
                cuadroVisual1["text"]=data.split(",")[2]
                
    finally:
        if device is not None and device.is_open():
            device.close()        


#--------------------Boton que llama a la función CodigoIniciar--------------

botonEnvio=Button(miframe, text=" Iniciar " ,command=codigoIniciar)
botonEnvio.grid(row=10, column= 10, padx= 5, pady=5, columnspan= 2, )
botonEnvio.config(bg="#FA991C")
botonEnvio.pack()

#----------------Loop de la ventana  --------------

raiz.mainloop()

Attached Files

Thumbnail(s)
   
Reply


Messages In This Thread
Anyone know what happened to my button? - by IgnacioMora23 - May-28-2021, 11:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 2,980 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020