Selasa, 24 Oktober 2023

Belajar Python 2 GUI sederhana

 Untuk membuat GUI di python memang memerlukan lebih efort 

https://realpython.com/pysimplegui-python/

https://www.pysimplegui.org/en/latest/

 

program tambah tambahan

 import PySimpleGUI as sg

sg.theme('DarkAmber')   # Add a touch of color
#  python C:\Users\Dell\python\GUI4.py
# penambahan
layout = [  [sg.Text('Masukan angka ke 1'), sg.InputText(1)],

            [sg.Text('masukan angka ke 2'),sg.InputText(2)],
            [sg.Button('Ok'), sg.Button('Cancel')] ]

# Create the Window
window = sg.Window('Coba GUI', layout)
# Event Loop to process "events" and get the "values" of the inputs
while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED or event == 'Cancel': # if user closes window or clicks cancel
        break
    print('Angka 1= ', values[0])
    print('Angka 2= ', values[1])
    print('Angka 1 + angka 2 = ', int(values[1])+int(values[0]))
    #sg.Text(values[0]+values[1])
  # window('gelo')
window.close()

 


 

 import PySimpleGUI as sg
import serial

sg.theme('DarkAmber')   # Add a touch of color
#  python C:\Users\Dell\python\GUI5.py
# penambahan
layout = [  [sg.Text('Masukan Port Serial'), sg.InputText(1)],
            [sg.Button('Ok'), sg.Button('Cancel')]
         ]
 
# Create the Window
window = sg.Window('Coba GUI Serial port', layout)
# Event Loop to process "events" and get the "values" of the inputs
ser = serial.Serial('COM5',baudrate=9600,timeout=1)
while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED or event == 'Cancel': # if user closes window or clicks cancel
        break
    
    arduinoData = ser.readline()
    print(arduinoData)
   
window.close()

 


 

 

 



Tidak ada komentar:

Posting Komentar