knute
Posts: 477
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

Re: Old-school GUI - Possible? (Beware, silly purpose)

Sat Aug 17, 2019 7:37 pm

And an example of setting up your menu with buttons. You will see right away why I used the labels in the original but it does work.

Code: Select all

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Buttons extends JFrame {
    private Color mBlue = new Color(0x3e86ca);
    private Color mGreen = new Color(0x0a6221);

    public Buttons() {
        super("Buttons");
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

        JPanel panel = new JPanel(new GridBagLayout());
        panel.setOpaque(true);
        panel.setBackground(Color.BLACK);

        GridBagConstraints c = new GridBagConstraints();
        c.insets = new Insets(5,5,5,5);
        c.anchor = GridBagConstraints.WEST;
        c.gridx = 0;

        McButton mb1 = new McButton("F1 > MEDICAL RESOURCE CENTER");
        mb1.addActionListener(event ->
         JOptionPane.showMessageDialog(mb1,"Button 1"));
        McButton mb2 = new McButton("F2 > LIMB REPLACEMENT");
        mb2.addActionListener(event ->
         JOptionPane.showMessageDialog(mb1,"Button 2"));
        McButton mb3 = new McButton("F3 > MEMBER ASSISTANCE");
        mb3.addActionListener(event ->
         JOptionPane.showMessageDialog(mb1,"Button 3"));

        panel.add(mb1,c);
        panel.add(mb2,c);
        panel.add(mb3,c);

        add(panel,BorderLayout.CENTER);

        pack();
        setVisible(true);
    }

    public class McButton extends JButton implements FocusListener {
        public McButton(String label) {
            super(label);

            setFont(new Font(Font.SANS_SERIF,Font.BOLD,24));
            setForeground(mBlue);
            setBackground(Color.BLACK);
            setOpaque(true);
            addFocusListener(this);
        }

        public void focusGained(FocusEvent fe) {
            setForeground(Color.BLACK);
            setBackground(mGreen);
        }

        public void focusLost(FocusEvent fe) {
            setForeground(mBlue);
            setBackground(Color.BLACK);
        }
    }

    public static void main(String... args) {
        EventQueue.invokeLater(() -> new Buttons());
    }
}


gmeader
Posts: 6
Joined: Mon Aug 07, 2017 11:21 pm

Re: Old-school GUI - Possible? (Beware, silly purpose)

Mon Sep 16, 2019 10:40 pm

Easiest Python GUI of all:
PySimpleGUI

http://www.pysimplegui.org

Python GUI For Humans - Transforms tkinter, Qt, Remi, WxPython into portable people-friendly Pythonic interfaces

Spaziba
Posts: 25
Joined: Mon Apr 30, 2018 4:31 pm

Re: Old-school GUI - Possible? (Beware, silly purpose)

Tue Sep 17, 2019 6:16 pm

gmeader wrote:
Mon Sep 16, 2019 10:40 pm
Easiest Python GUI of all:
PySimpleGUI

http://www.pysimplegui.org

Python GUI For Humans - Transforms tkinter, Qt, Remi, WxPython into portable people-friendly Pythonic interfaces
Another nice advice, thanks.
A have not followed up here, sorry. The interface is all but finished at the moment thanks to an enormous help from Knute. It is all done in java and works completely as my original post wished for. Super help considering a completely inexperienced user (me) was able to catch on a complete the interface.

Return to “Python”