I have some code that can help me find i2c addresses (from MCP23017 devices). For every device it finds it creates a label with two radio buttons next to it, where the user has a choice of selecting the corresponding address as an input or output. (So that the GPIO on that mcp becomes all inputs or all outputs.)
Can somebody help me get functionality to these radio buttons as when selecting it as input or output, because now there just labels and the radio buttons are not connected to these labels.
Or is it better not to use a for loop for creating variable buttons/labels (, because of ...)?
Goal: For every live address select it as input or output, then save these choices by clicking a button and the code configures the mcp on the live addresses as inputs or outputs.
thanks in advance!
this is my code so far:
Code: Select all
from smbus2 import SMBus, i2c_msg from tkinter import * from tkinter.ttk import * from tkinter import messagebox ##channel = 1 ##i2c = SMBus(channel) with SMBus(1) as bus: dev =  for addr in range(32,40): #mcp addresses range from 0x20 to 0x27 try: msg = i2c_msg.read(addr,4) bus.i2c_rdwr(msg) msg= i2c_msg.write(addr,4) bus.i2c_rdwr(msg) except IOError: print("No addr on" , addr) else: dev+= [addr] print(addr) print(dev) print("I found I2C devices on address:", *dev,sep="\n") window = Tk() window.title("IO Module") window.geometry('350x200') for i in range(len(dev)): lbl = Label(window,text = dev[0+i],relief="groove",borderwidth = 5) lbl.grid(column=0,row=0+i,padx=10) rad = Radiobutton(window, text='Input', value = 1+i) rad1 = Radiobutton(window, text='Output',value = 9+i) rad.grid(column=1, row = 0+i) rad1.grid(column=2,row=0+i) window.mainloop()