hi, I am a novice in programming I am woodworker :D
here is my question: how to select com port from spinbox and make connect button
code:
here is my question: how to select com port from spinbox and make connect button
code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
#!/usr/bin/env python import tkinter from tkinter import ttk import serial import time # importuj kniznicu import serial.tools.list_ports # importuj kniznicu pre skenovanie com portov import sys root = tkinter.Tk() ports = serial.tools.list_ports.comports( include_links = False ) # skenovanie com portov selected_lang = tkinter.StringVar() langs = (ports) spinbox = tkinter.Spinbox(root, values = langs, width = 10 , textvariable = selected_lang, wrap = True ) Arduino_Serial = serial.Serial( "COM7" , 9600 ) print (Arduino_Serial.readline().decode( 'utf-8' )) def on(): Arduino_Serial.write(b '1' ) print (Arduino_Serial.readline()) def off(): Arduino_Serial.write(b '0' ) print (Arduino_Serial.readline()) showButton = ttk.Button(root, text = "turn on led" , command = on) showButton1 = ttk.Button(root, text = "turn off led" , command = off) spinbox.grid(column = 1 , row = 1 ) showButton.grid(column = 2 , row = 1 ) showButton1.grid(column = 2 , row = 2 ) root.mainloop() |