0

I'm doing a project where I read info from a socket and then intend to display it on a gui using tkinter. The thing is, my read info from socket is a loop and for the gui I need another loop.

I'm pretty inexperienced with both Python and Tkinter, which probably explains my mistake here.

The fd_dict is a dictionary with the properties and respective values of a car ex: gear, power, speed, etc (theme of my project).

The main problem is either I get the values from the socket or I display the gui, never both obviously, since it stays on the earlier loop.

while True:
    # UDP server part of the connection
    message, address = server_socket.recvfrom(1024)
    del address
    fdp = ForzaDataPacket(message)
    fdp.wall_clock = dt.datetime.now()

    # Get all properties
    properties = fdp.get_props()
    # Get parameters
    data = fdp.to_list(params)
    assert len(data) == len(properties)
    # Zip into a dictionary
    fd_dict = dict(zip(properties, data))
    # Add timestamp
    fd_dict['timestamp'] = str(fdp.wall_clock)
    
    # Print of various testing values
    print('GEAR: ', fd_dict['gear'])
    print('SPEED(in KMH): ', fd_dict['speed'] * 3.6) #speed in kph
    print('POWER(in HP): ', fd_dict['power'] * 0.0013596216173) #power in hp
    #print('PERFORMANCE INDEX: ', fd_dict['car_performance_index'])
    print('\n')

The tkinter code:

window = Tk()
window.title('Forza Horizon 5 Telemetry')
window.geometry("1500x800")
window.configure(bg="#1a1a1a")

frame = Frame(window)
frame.pack()

label_gear = Label(text = '0')
label_gear.configure(bg="darkgrey")
label_gear.pack()

I read about using after() and using classes, but I've never used them, and can't figure out how to apply them here.

Thanks in advance.

3
  • How fast does the data come in on the socket? If your program only read from the socket every 100ms or so, would that be a problem? Commented Jun 21, 2022 at 20:49
  • I actually don't know since the origin isn't "controlled" by me. It's a game (FH5) where I'm getting the data from. But I imagine it would be either 100ms or 50ms, from other implementations I've seen in another languages Commented Jun 22, 2022 at 8:06
  • You should be able to measure this. Just run your program without tkinter and measure how fast you're reading the data. Commented Jun 22, 2022 at 14:01

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.