Advertisement
afrizalwahyuadi66

GUI

May 19th, 2024 (edited)
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.56 KB | Source Code | 0 0
  1. import PySimpleGUI as sg
  2. import pandas as pd
  3.  
  4. sg.theme('DarkGreen4') #Dari Library PySimpleGUI
  5.  
  6. EXCEL_FILE = 'Pendaftaran.xlsx'
  7.  
  8. df = pd.read_excel(EXCEL_FILE) #Dari library pandas
  9.  
  10. #----------------DARI LIBRARY "PySimpleGUI"--------------------
  11. layout=[
  12. [sg.Text('Masukan Data Kamu')],
  13. [sg.Text('Nama',size=(15,1)), sg.InputText(key='Nama')],
  14. [sg.Text('Nomor',size=(15,1)), sg.InputText(key='Nomor')],
  15. [sg.Text('Alamat',size=(15,1)), sg.Multiline(key='Alamat')],
  16. [sg.Text('Tanggal Lahir',size=(15,1)), sg.InputText(key='Tanggal Lahir'),
  17.                                         sg.CalendarButton('Kalender', target='Tanggal Lahir', format=('%d-%m-%y'))],
  18. [sg.Text('Jenis Kelamin',size=(15,1)), sg.Combo(['Pria','Wanita'],key='Jenis Kelamin')],
  19. [sg.Text('Hobby',size=(15,1)), sg.Checkbox('Belajar',key='Belajar'),
  20.                              sg.Checkbox('Menonton',key='Menonton'),
  21.                               sg.Checkbox('Music',key='Music')],
  22. [sg.Submit(), sg.Button('clear'), sg.Exit()]
  23. ]
  24. #---------------------------------------------------------------
  25.  
  26. window=sg.Window('Form pendaftaran',layout)
  27.  
  28. def clear_input():
  29.     for key in values:
  30.         window[key]('')
  31.         return None
  32.  
  33. while True :
  34.     event, values = window.read()
  35.     if event == sg.WIN_CLOSED or event == 'EXIT':
  36.        break
  37.     if event == 'Clear':
  38.         clear_input()
  39.     if event == 'Submit':
  40.         df =df._append(values, ignore_index=True)
  41.         df.to_excel(EXCEL_FILE, index=False)
  42.         sg.popup('Data Berhasil di Simpan')
  43.         clear_input()
  44. window.close()
  45.  
Tags: entry
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement