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?
#3
(May-28-2021, 11:20 PM)Larz60+ Wrote: you cant use both pack and grid in same container,
Try removing line 45, and change all other packs (within the miframe) to grid as well.
or all grids to pack, but not both.


Ready, the button appears. Thank you.

The idea of the button is that when I write it, it sends a message and opens the "port" or "xbee" so that it receives a message "infinite times".
As you can see in the image that just uploaded, when I click the button, the message is sent and in a couple of milliseconds I get the first information about the incoming frame. Which is good.

But when I want to get from that same data frame, the time or the date, my system stops working. I don't know if you know why this is happening?

I am simulating this programming, sending the frames from an Xbee to an Arduino, so on the right of the image you can see the arduino serial monitor. And on the left of the image the interface that I designed.

Another problem I have is that the value is not updated and only the first value I read is frozen.


#-----------------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="#919F89")

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="#98A7AC")
 
#-----------------Valores por Mostrar en la Pantallas-----------------

voltage = StringVar()
 
#--------------- Cuadros donde se muestran datos-----------------------
 
cuadroVisual1= Entry(miframe, textvariable = voltage)
cuadroVisual1.grid(row=1, column= 1, padx=1, pady=5)
cuadroVisual1.config(fg="black",justify="center")

 
cuadroVisual2= Entry(miframe, textvariable = voltage)
cuadroVisual2.grid(row=2, column= 1, padx=1, pady=5)
cuadroVisual2.config(fg="black",justify="center")
 
cuadroVisual3= Entry(miframe, textvariable = voltage)
cuadroVisual3.grid(row=4, column= 1, padx=1, pady=5)
cuadroVisual3.config(fg="black",justify="center")
 
cuadroVisual4= Entry(miframe, textvariable=voltage)
cuadroVisual4.grid(row=5, column= 1, padx=1, pady=5)
cuadroVisual4.config(fg="black",justify="center")
 
cuadroVisual5= Entry(miframe, textvariable=voltage)
cuadroVisual5.grid(row=6, column= 1, padx=1, pady=5)
cuadroVisual5.config(fg="black",justify="center")
 
cuadroVisual6= Entry(miframe, textvariable=voltage)
cuadroVisual6.grid(row=7, column= 1, padx=1, pady=5)
cuadroVisual6.config(fg="black",justify="center")
 
cuadroVisual7= Entry(miframe, textvariable=voltage)
cuadroVisual7.grid(row=9, column= 1, padx=1, pady=5)
cuadroVisual7.config(fg="black",justify="center")
 
#----------------Cuadros donde esta el Texto "Voltage de Panel 1"--------
 
miLabel=Label(miframe, text="Sistema de monitoreo de Paneles del SESLab", font=18)
miLabel.grid(row=0, column= 0, padx= 5, pady=5, columnspan= 2)
 
nombrePanel=Label(miframe, text="Fecha de medición : ")
nombrePanel.grid(row=1, column= 0, padx= 2, pady=5)
 
nombrePanel=Label(miframe, text="Hora de medición : ")
nombrePanel.grid(row=2, column= 0, padx= 2, pady=5)
 
nombrePanel=Label(miframe, text="Voltage de Panel 1 : ")
nombrePanel.grid(row=4, column= 0, padx= 2, pady=5)
 
nombrePanel=Label(miframe, text="Voltage de Panel 2 : ")
nombrePanel.grid(row=5, column= 0, padx= 2, pady=5)
 
nombrePanel=Label(miframe, text="Voltage de Panel 3 : ")
nombrePanel.grid(row=6, column= 0, padx= 2, pady=5)
 
nombrePanel=Label(miframe, text="Promedio : ")
nombrePanel.grid(row=7, column= 0, padx= 2, pady=5)
 
nombrePanel=Label(miframe, text="Panel con Menor Voltaje : ")
nombrePanel.grid(row=9, column= 0, padx= 2, pady=5)
 
#----------------Función que manda un mensaje Broadcast a Xbees---------
 
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])
                
    finally:
        if device is not None and device.is_open():
            device.close()        


#----------------Boton que llama a la función CodigoIniciar--------------
 
botonEnvio=Button(raiz, bg="#E2BBAC", text="Iniciar " ,command=codigoIniciar)
botonEnvio.pack()
 
#----------------Loop de la ventana  --------------
 
raiz.mainloop()

Attached Files

Thumbnail(s)
   
Reply


Messages In This Thread
RE: Anyone know what happened to my button? - by IgnacioMora23 - May-29-2021, 02:41 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 4,951 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