Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
stc19007 authored Oct 18, 2024
1 parent 1616d02 commit 8f73a1a
Showing 1 changed file with 301 additions and 0 deletions.
301 changes: 301 additions & 0 deletions SDPPython/gui.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,301 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import tkinter as tk\n",
"from tkinter import ttk\n",
"\n",
"def option_selected(event):\n",
" print(f\"Selected: {dropdown_var.get()}\")\n",
"\n",
"root = tk.Tk()\n",
"root.title(\"Tkinter GUI\")\n",
"\n",
"# drop-down menu\n",
"dropdown_var = tk.StringVar()\n",
"dropdown = ttk.Combobox(root, textvariable=dropdown_var)\n",
"dropdown['values'] = ('Option 1', 'Option 2', 'Option 3')\n",
"dropdown.grid(row=0, column=0, padx=10, pady=10)\n",
"dropdown.bind(\"<<ComboboxSelected>>\", option_selected)\n",
"\n",
"# buttons\n",
"button1 = tk.Button(root, text=\"Button 1\")\n",
"button1.grid(row=0, column=1, padx=10)\n",
"\n",
"button2 = tk.Button(root, text=\"Button 2\")\n",
"button2.grid(row=0, column=2, padx=10)\n",
"\n",
"button3 = tk.Button(root, text=\"Button 3\")\n",
"button3.grid(row=0, column=3, padx=10)\n",
"\n",
"root.mainloop()\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"ename": "SystemExit",
"evalue": "0",
"output_type": "error",
"traceback": [
"An exception has occurred, use %tb to see the full traceback.\n",
"\u001b[1;31mSystemExit\u001b[0m\u001b[1;31m:\u001b[0m 0\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"C:\\Users\\steve\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\site-packages\\IPython\\core\\interactiveshell.py:3585: UserWarning: To exit: use 'exit', 'quit', or Ctrl-D.\n",
" warn(\"To exit: use 'exit', 'quit', or Ctrl-D.\", stacklevel=1)\n"
]
}
],
"source": [
"import sys\n",
"from PyQt5.QtWidgets import QApplication, QWidget, QComboBox, QPushButton, QHBoxLayout, QVBoxLayout\n",
"\n",
"def on_selection_change(text):\n",
" print(f\"Selected: {text}\")\n",
"\n",
"app = QApplication(sys.argv)\n",
"window = QWidget()\n",
"window.setWindowTitle(\"PyQt5 GUI\")\n",
"\n",
"# layouts\n",
"main_layout = QHBoxLayout()\n",
"left_layout = QVBoxLayout()\n",
"right_layout = QVBoxLayout()\n",
"\n",
"# drop-down menu\n",
"dropdown = QComboBox()\n",
"dropdown.addItems(['Option 1', 'Option 2', 'Option 3'])\n",
"dropdown.currentTextChanged.connect(on_selection_change)\n",
"left_layout.addWidget(dropdown)\n",
"\n",
"# buttons\n",
"button1 = QPushButton(\"Button 1\")\n",
"button2 = QPushButton(\"Button 2\")\n",
"button3 = QPushButton(\"Button 3\")\n",
"right_layout.addWidget(button1)\n",
"right_layout.addWidget(button2)\n",
"right_layout.addWidget(button3)\n",
"\n",
"main_layout.addLayout(left_layout)\n",
"main_layout.addLayout(right_layout)\n",
"\n",
"window.setLayout(main_layout)\n",
"window.show()\n",
"sys.exit(app.exec_())\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"ename": "OSError",
"evalue": "source code not available",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mOSError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[3], line 33\u001b[0m\n\u001b[0;32m 30\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSelected: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mtext\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 32\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;18m__name__\u001b[39m \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m__main__\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[1;32m---> 33\u001b[0m \u001b[43mMyApp\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mrun\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[1;32m~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\site-packages\\kivy\\app.py:955\u001b[0m, in \u001b[0;36mApp.run\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 952\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mrun\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[0;32m 953\u001b[0m \u001b[38;5;250m \u001b[39m\u001b[38;5;124;03m'''Launches the app in standalone mode.\u001b[39;00m\n\u001b[0;32m 954\u001b[0m \u001b[38;5;124;03m '''\u001b[39;00m\n\u001b[1;32m--> 955\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_run_prepare\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 956\u001b[0m runTouchApp()\n\u001b[0;32m 957\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_stop()\n",
"File \u001b[1;32m~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\site-packages\\kivy\\app.py:924\u001b[0m, in \u001b[0;36mApp._run_prepare\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 922\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbuilt:\n\u001b[0;32m 923\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mload_config()\n\u001b[1;32m--> 924\u001b[0m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mload_kv\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfilename\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mkv_file\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 925\u001b[0m root \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mbuild()\n\u001b[0;32m 926\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m root:\n",
"File \u001b[1;32m~\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python310\\site-packages\\kivy\\app.py:677\u001b[0m, in \u001b[0;36mApp.load_kv\u001b[1;34m(self, filename)\u001b[0m\n\u001b[0;32m 675\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 676\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n\u001b[1;32m--> 677\u001b[0m default_kv_directory \u001b[38;5;241m=\u001b[39m dirname(\u001b[43mgetfile\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[38;5;18;43m__class__\u001b[39;49m\u001b[43m)\u001b[49m)\n\u001b[0;32m 678\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m default_kv_directory \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[0;32m 679\u001b[0m default_kv_directory \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m'\u001b[39m\n",
"File \u001b[1;32mC:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.10_3.10.3056.0_x64__qbz5n2kfra8p0\\lib\\inspect.py:785\u001b[0m, in \u001b[0;36mgetfile\u001b[1;34m(object)\u001b[0m\n\u001b[0;32m 783\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m module\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__file__\u001b[39m\n\u001b[0;32m 784\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mobject\u001b[39m\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__module__\u001b[39m \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m__main__\u001b[39m\u001b[38;5;124m'\u001b[39m:\n\u001b[1;32m--> 785\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mOSError\u001b[39;00m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124msource code not available\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m 786\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mTypeError\u001b[39;00m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m{!r}\u001b[39;00m\u001b[38;5;124m is a built-in class\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;241m.\u001b[39mformat(\u001b[38;5;28mobject\u001b[39m))\n\u001b[0;32m 787\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m ismethod(\u001b[38;5;28mobject\u001b[39m):\n",
"\u001b[1;31mOSError\u001b[0m: source code not available"
]
},
{
"ename": "",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[1;31mThe Kernel crashed while executing code in the current cell or a previous cell. \n",
"\u001b[1;31mPlease review the code in the cell(s) to identify a possible cause of the failure. \n",
"\u001b[1;31mClick <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. \n",
"\u001b[1;31mView Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details."
]
}
],
"source": [
"from kivy.app import App\n",
"from kivy.uix.boxlayout import BoxLayout\n",
"from kivy.uix.button import Button\n",
"from kivy.uix.spinner import Spinner\n",
"\n",
"class MyApp(App):\n",
" def build(self):\n",
" # main layout\n",
" layout = BoxLayout(orientation='horizontal', padding=10, spacing=10)\n",
"\n",
" # drop-down menu\n",
" dropdown = Spinner(\n",
" text='Choose Option',\n",
" values=('Option 1', 'Option 2', 'Option 3'),\n",
" size_hint=(0.3, None), # Take 30% width, fix height\n",
" height=50 # Set a specific height to prevent the dropdown from expanding too much\n",
" )\n",
" dropdown.bind(text=self.on_selection_change)\n",
"\n",
" # buttons\n",
" button1 = Button(text='Button 1', size_hint=(0.2, None), height=50) # 20% width, fixed height\n",
" button2 = Button(text='Button 2', size_hint=(0.2, None), height=50)\n",
" button3 = Button(text='Button 3', size_hint=(0.2, None), height=50)\n",
"\n",
" # widgets\n",
" layout.add_widget(dropdown)\n",
" layout.add_widget(button1)\n",
" layout.add_widget(button2)\n",
" layout.add_widget(button3)\n",
"\n",
" return layout\n",
"\n",
" def on_selection_change(self, spinner, text):\n",
" print(f\"Selected: {text}\")\n",
"\n",
"if __name__ == '__main__':\n",
" MyApp().run()\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"ename": "PyNoAppError",
"evalue": "The wx.App object must be created first!",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mPyNoAppError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[7], line 40\u001b[0m\n\u001b[0;32m 37\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mSelected: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mselected\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 39\u001b[0m app \u001b[38;5;241m=\u001b[39m wx\u001b[38;5;241m.\u001b[39mApp(\u001b[38;5;28;01mFalse\u001b[39;00m)\n\u001b[1;32m---> 40\u001b[0m frame \u001b[38;5;241m=\u001b[39m \u001b[43mMyFrame\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 41\u001b[0m app\u001b[38;5;241m.\u001b[39mMainLoop()\n",
"Cell \u001b[1;32mIn[7], line 5\u001b[0m, in \u001b[0;36mMyFrame.__init__\u001b[1;34m(self)\u001b[0m\n\u001b[0;32m 4\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m__init__\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[1;32m----> 5\u001b[0m \u001b[38;5;28;43msuper\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[38;5;21;43m__init__\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mtitle\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mwxPython GUI\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msize\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m300\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m200\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 7\u001b[0m panel \u001b[38;5;241m=\u001b[39m wx\u001b[38;5;241m.\u001b[39mPanel(\u001b[38;5;28mself\u001b[39m)\n\u001b[0;32m 9\u001b[0m \u001b[38;5;66;03m# Drop-down menu (wx.ComboBox in wxPython)\u001b[39;00m\n",
"\u001b[1;31mPyNoAppError\u001b[0m: The wx.App object must be created first!"
]
}
],
"source": [
"import wx\n",
"\n",
"class MyFrame(wx.Frame):\n",
" def __init__(self):\n",
" super().__init__(None, title=\"wxPython GUI\", size=(300, 200))\n",
" \n",
" panel = wx.Panel(self)\n",
"\n",
" # drop-down menu\n",
" self.dropdown = wx.ComboBox(panel, choices=['Option 1', 'Option 2', 'Option 3'], style=wx.CB_READONLY)\n",
" self.dropdown.Bind(wx.EVT_COMBOBOX, self.on_selection)\n",
"\n",
" # buttons\n",
" button1 = wx.Button(panel, label=\"Button 1\")\n",
" button2 = wx.Button(panel, label=\"Button 2\")\n",
" button3 = wx.Button(panel, label=\"Button 3\")\n",
"\n",
" # layout\n",
" hbox = wx.BoxSizer(wx.HORIZONTAL)\n",
" vbox_left = wx.BoxSizer(wx.VERTICAL)\n",
" vbox_right = wx.BoxSizer(wx.VERTICAL)\n",
"\n",
" vbox_left.Add(self.dropdown, flag=wx.EXPAND | wx.ALL, border=10)\n",
" vbox_right.Add(button1, flag=wx.EXPAND | wx.ALL, border=10)\n",
" vbox_right.Add(button2, flag=wx.EXPAND | wx.ALL, border=10)\n",
" vbox_right.Add(button3, flag=wx.EXPAND | wx.ALL, border=10)\n",
"\n",
" hbox.Add(vbox_left, proportion=1, flag=wx.EXPAND)\n",
" hbox.Add(vbox_right, proportion=1, flag=wx.EXPAND)\n",
"\n",
" panel.SetSizer(hbox)\n",
"\n",
" self.Show()\n",
"\n",
" def on_selection(self, event):\n",
" selected = self.dropdown.GetValue()\n",
" print(f\"Selected: {selected}\")\n",
"\n",
"app = wx.App(False)\n",
"frame = MyFrame()\n",
"app.MainLoop()\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "module 'dearpygui.dearpygui' has no attribute 'combo'",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[8], line 14\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[38;5;66;03m# Main window\u001b[39;00m\n\u001b[0;32m 11\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m dpg\u001b[38;5;241m.\u001b[39mwindow(label\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDear PyGui Window\u001b[39m\u001b[38;5;124m\"\u001b[39m, width\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m300\u001b[39m, height\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m200\u001b[39m):\n\u001b[0;32m 12\u001b[0m \n\u001b[0;32m 13\u001b[0m \u001b[38;5;66;03m# Drop-down menu\u001b[39;00m\n\u001b[1;32m---> 14\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[43mdpg\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcombo\u001b[49m(label\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mOptions\u001b[39m\u001b[38;5;124m\"\u001b[39m, items\u001b[38;5;241m=\u001b[39m[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mOption 1\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mOption 2\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mOption 3\u001b[39m\u001b[38;5;124m\"\u001b[39m], callback\u001b[38;5;241m=\u001b[39mdropdown_callback):\n\u001b[0;32m 15\u001b[0m \u001b[38;5;28;01mpass\u001b[39;00m\n\u001b[0;32m 17\u001b[0m \u001b[38;5;66;03m# Buttons\u001b[39;00m\n",
"\u001b[1;31mAttributeError\u001b[0m: module 'dearpygui.dearpygui' has no attribute 'combo'"
]
}
],
"source": [
"import dearpygui.dearpygui as dpg\n",
"\n",
"# callback\n",
"def dropdown_callback(sender, app_data):\n",
" print(f\"Selected: {app_data}\")\n",
"\n",
"# context\n",
"dpg.create_context()\n",
"\n",
"# main window\n",
"with dpg.window(label=\"Dear PyGui Window\", width=300, height=200):\n",
" \n",
" # drop-down menu\n",
" dpg.add_combo(label=\"Options\", items=[\"Option 1\", \"Option 2\", \"Option 3\"], callback=dropdown_callback)\n",
" \n",
" # buttons\n",
" dpg.add_button(label=\"Button 1\")\n",
" dpg.add_button(label=\"Button 2\")\n",
" dpg.add_button(label=\"Button 3\")\n",
"\n",
"# start\n",
"dpg.create_viewport(title='Dear PyGui GUI', width=300, height=200)\n",
"dpg.setup_dearpygui()\n",
"dpg.show_viewport()\n",
"dpg.start_dearpygui()\n",
"dpg.destroy_context()\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.11"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 8f73a1a

Please sign in to comment.