Python Forum
[PyGUI] From comand line to GUI
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyGUI] From comand line to GUI
#1
Command line to GUI!
Hi! I am working as a teacher in a school in Sweden. I have created a simpel program that takes a date and then calculates the next date. The dates are in a list and very simple takes the tenth date and prints it out in console. I would like to have a more usable program, GUI for this task, but i am struggeling to make it funktione.
#A list with possible dates for a visit  

 
visit2 = ["2019-10-14","2019-10-15","2019-10-16","2019-10-17","2019-10-18","2019-10-21","2019-10-22","2019-10-23","2019-10-24","2019-10-25","2019-11-07","2019-11-08","2019-11-14","2019-11-15","2019-11-21","2019-11-28","2019-11-29","2019-12-05","2019-12-06","2019-12-12","2019-12-13","2019-12-16","2019-12-17","2019-12-18","2019-12-19","2020-01-15","2020-01-16","2020-01-23","2020-01-24","2020-01-30","2020-01-31","2020-02-06","2020-02-07","2020-02-13","2020-02-14","2020-02-17","2020-02-18","2020-02-19","2020-02-20","2020-02-21","2020-03-02","2020-03-03","2020-03-04","2020-03-05","2020-03-06","2020-03-09","2020-03-10","2020-03-11","2020-03-12","2020-03-13","2020-03-19","2020-03-20","2020-03-26","2020-03-27","2020-04-02","2020-04-03","2020-04-09","2020-04-24","2020-04-30","2020-05-07","2020-05-08","2020-05-15","2020-05-25","2020-05-26","2020-05-27","2020-05-28","2020-05-29","2020-06-01","2020-06-02","2020-06-03","2020-06-04","2020-06-05"]


date = (input("When was the last visit?: Use YYYY-MM-DD syntax: ")) 
print() 

#When you done a visit and you done the input, next visit prints out in console , it should be aproximative every 10 day


print("Well the next visit should be at: "+visit2[visit2.index(date)+10])
The nerest i have come today whith tkinter and Qt is
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 10 19:05:50 2019

@author: Mats
"""

import tkinter
from tkinter import *

root=Tk()
root.title('mats')
sizex = 400
sizey = 300

root.wm_geometry("%dx%d" % (sizex, sizey))

F1 = tkinter.Frame()


s = tkinter.Scrollbar(F1)
L = tkinter.Listbox(F1)

s.pack(side=tkinter.RIGHT, fill=tkinter.Y)
L.pack(side=tkinter.LEFT, fill=tkinter.Y)

s['command'] = L.yview
L['yscrollcommand'] = s.set



itemsforlistbox=['2019-10-14','2019-10-15','2019-10-16','2019-10-17','2019-10-18','2019-10-21','2019-10-22','2019-10-23','2019-10-24','2019-10-25','2019-11-07','2019-11-08','2019-11-14','2019-11-15','2019-11-21','2019-11-28','2019-11-29','2019-12-05','2019-12-06','2019-12-12','2019-12-13','2019-12-16','2019-12-17','2019-12-18','2019-12-19','2020-01-15','2020-01-16','2020-01-23','2020-01-24','2020-01-30','2020-01-31','2020-02-06','2020-02-07','2020-02-13','2020-02-14','2020-02-17','2020-02-18','2020-02-19','2020-02-20','2020-02-21','2020-03-02','2020-03-03','2020-03-04','2020-03-05','2020-03-06','2020-03-09','2020-03-10','2020-03-11','2020-03-12','2020-03-13','2020-03-19','2020-03-20','2020-03-26','2020-03-27','2020-04-02','2020-04-03','2020-04-09','2020-04-24','2020-04-30','2020-05-07','2020-05-08','2020-05-15','2020-05-25','2020-05-26','2020-05-27','2020-05-28','2020-05-29','2020-06-01','2020-06-02','2020-06-03','2020-06-04','2020-06-05']



for items in itemsforlistbox:
    L.insert(END,items)





F1.pack(side=tkinter.TOP)

F2 = tkinter.Frame()
mats = tkinter.Label(F2)

def poll():
    mats.after(200, poll)
    sel = L.curselection()

   
    mats.config(text=str(sel))
   
    

mats.pack()
F2.pack(side=tkinter.TOP)

poll()
root.mainloop()
And something similar with Qt
import sys

from PyQt5.QtWidgets import QWidget, QListWidget, QMessageBox, QApplication

class MyWindow(QWidget):
    """Main Window class for our application"""

    def __init__(self):
        """Class konstruktor"""
        super().__init__()

        self.init_gui()

    def init_gui(self):
        """Skapa gränssnitt"""

        # Sätt fönsteregenskaper

        self.resize(400,200)
        self.move(50,50)
        self.setWindowTitle("APL-Besök")

        # Skapa listkontroll

        self.list_box = QListWidget(self)
        self.list_box.move(20,20)
        self.list_box.resize(100,100)

        # Lägg till alternativ i listan

        itemsforlistbox=['2019-10-14','2019-10-15','2019-10-16','2019-10-17','2019-10-18','2019-10-21','2019-10-22','2019-10-23','2019-10-24','2019-10-25','2019-11-07','2019-11-08','2019-11-14','2019-11-15','2019-11-21','2019-11-28','2019-11-29','2019-12-05','2019-12-06','2019-12-12','2019-12-13','2019-12-16','2019-12-17','2019-12-18','2019-12-19','2020-01-15','2020-01-16','2020-01-23','2020-01-24','2020-01-30','2020-01-31','2020-02-06','2020-02-07','2020-02-13','2020-02-14','2020-02-17','2020-02-18','2020-02-19','2020-02-20','2020-02-21','2020-03-02','2020-03-03','2020-03-04','2020-03-05','2020-03-06','2020-03-09','2020-03-10','2020-03-11','2020-03-12','2020-03-13','2020-03-19','2020-03-20','2020-03-26','2020-03-27','2020-04-02','2020-04-03','2020-04-09','2020-04-24','2020-04-30','2020-05-07','2020-05-08','2020-05-15','2020-05-25','2020-05-26','2020-05-27','2020-05-28','2020-05-29','2020-06-01','2020-06-02','2020-06-03','2020-06-04','2020-06-05']

        for items in itemsforlistbox:
             self.list_box.addItem(items)



      #  for i in range(100):
       #     self.list_box.addItem("Alternativ %d" % i)

        # Sätt standardalternativet till rad 0

        self.list_box.setCurrentRow(0)

        # Koppla en händelsemetod till signal

        self.list_box.currentRowChanged.connect(self.on_current_row_changed)

    def on_current_row_changed(self, curr):
        """Hantera signalen currentRowChanged"""

        QMessageBox.information(self, "Meddelande", "Senaste besöket: " + str(curr))
        QMessageBox.information(self, "Meddelande", "Nästa besök: " + self.list_box.currentItem().text())
        

"""
    def CurSelet(event):
        widget = event.widget
        selection=widget.curselection()
        picked = widget.get(selection[0]+10)
        print(picked)
"""








if __name__ == '__main__':

    app = QApplication(sys.argv)

    window = MyWindow()
    window.show()

    sys.exit(app.exec_())
Instead of the index, I want the value that is indexed.
Reply


Messages In This Thread
From comand line to GUI - by elmatte - Dec-23-2019, 09:18 AM
RE: From comand line to GUI - by DeaD_EyE - Dec-23-2019, 10:01 AM
RE: From comand line to GUI - by Denni - Dec-23-2019, 03:32 PM
RE: From comand line to GUI - by elmatte - Dec-24-2019, 11:32 AM
RE: From comand line to GUI - by elmatte - Dec-24-2019, 07:12 PM
RE: From comand line to GUI - by Denni - Dec-26-2019, 03:20 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020