Python Forum
popup, text input with two readable buttons
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
popup, text input with two readable buttons
#1
I need a pop-up message that will take a text input. I need a button to submit the input and one to abort the entire program. I have one solution, but I would rather have one that I am not paying $99 per year for a pop-up. Here is what I have. Could you guys show me another way to do the pop-up?

for x in range (numberOfFiles):
    row_data = read_data.iloc[x]
    ts = row_data.iloc[0]
    if ts == target_ts:
        target_row = x
        break

    if x == (numberOfFiles - 1):
        bad_ts = True

        while bad_ts:

             # setup message box
            layout = [[sg.Text('Invalid TS- number')],
                      [sg.Text('Enter valid number'), sg.InputText()],
                      [sg.Button('Submit'), sg.Button('Abort Test')]]

            # Create the Window
            window = sg.Window('Window Title', 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 == 'Abort Test':  # if user closes window or clicks cancel
                    if event ==  'Abort Test':
                        exit()
                    break

                target_ts = values[0]
                window.close()[/color]

            for x in range(numberOfFiles):
                row_data = read_data.iloc[x]
                ts = row_data.iloc[0]
                if ts == target_ts:
                    target_row = x
                    bad_ts = False
                    break
[Image: pop-up.jpg][/url][/img]
Larz60+ write Aug-28-2024, 07:22 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Tags have been added. Please use BBCode tags on future posts.
Reply
#2
What is sg?
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
(Aug-27-2024, 05:31 PM)menator01 Wrote: What is sg?

My question got closed from another forum because I used the names of packages that I had tried.

import PySimpleGUI as sg
Reply
#4
To be honest I would use tkinter. I can't see paying for something that I can get for free and seems to be easier to use.
Tkinter may be old but, is very easy to learn.
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#5
(Aug-27-2024, 06:10 PM)menator01 Wrote: To be honest I would use tkinter. I can't see paying for something that I can get for free and seems to be easier to use.
Tkinter may be old but, is very easy to learn.

Looking at the documentation for tkinter, pyqt5 and pyqt6; It looks like you have the choice of simple message boxes that do not have the capability or it is a full GUI app. That is why I am asking here. Or am I reading the docs and tutorials incorrectly? All I need is one fairly simple pop-up, and I do not want the be forced into re-structuring my entire program to be GUI driven.
Reply
#6
You may could do something like this. It's not the best approach but should give an idea.

import tkinter as tk

class Popup:
    def __init__(self, parent):
        self.parent = parent

        label = tk.Label(parent, text='Popup Window')
        label.grid(column=0, columnspan=2, row=0, sticky='new')
        label.configure(font=(None, 20, 'bold'))

        self.msg = tk.Label(parent)
        self.msg.grid(column=0, columnspan=2, row=1, sticky='new', padx=4, pady=4)
        self.msg.configure(
            highlightbackground = '#999999',
            highlightcolor = '#999999',
            highlightthickness = 1,
            bg = '#eeeeee'
        )

        label = tk.Label(parent, text='Number:')
        label.grid(column=0, row=2, sticky='new', pady=4, padx=2)

        self.entry = tk.Entry(parent)
        self.entry.grid(column=1, row=2, sticky='new', padx=2)

        btnframe = tk.Frame(parent)
        btnframe.grid(column=0, columnspan=2, row=3, sticky='new', pady=4)
        btnframe.columnconfigure(0, weight=3, uniform='btn')
        btnframe.columnconfigure(1, weight=3, uniform='btn')

        btn1 = tk.Button(btnframe, text='Submit', command=self.validate)
        btn1.grid(column=0, row=0, padx=2, pady=4)

        btn2 = tk.Button(btnframe, text='Cancel', command=parent.destroy)
        btn2.grid(column=1, row=0, padx=2, pady=4)

    def validate(self):
        number = self.entry.get()
        valid_numbers = [5,12,30,15]
        try:
            if int(number) not in valid_numbers:
                self.entry.delete(0, 'end')
                self.msg.configure(text=f'{number} is not valid')       
            else:
                self.parent.destroy()
        except ValueError:
            self.msg.configure(text='Please enter a number')
            self.entry.delete(0, 'end')


for i in range(100):
    if i == 35:
        root = tk.Tk()
        Popup(root)
        root.mainloop()
    else:
        print(i)
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#7
Thanks, that gives me a starting point!
Reply
#8
Subclass tkinter SimpleDialog to make any dialog you want.

https://docs.python.org/3/library/dialog.html
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Text input OK on Windows, not working on linux Ota 3 502 Sep-19-2024, 12:02 AM
Last Post: Ota
  [Tkinter] Tkinter popup no grabbing the selected keys - Event propagation Wehaveall 2 613 Aug-10-2024, 01:18 PM
Last Post: Wehaveall
  [PyQt] Hover over highlighted text and open popup window DrakeSoft 2 2,137 Oct-29-2022, 04:30 PM
Last Post: DrakeSoft
  [PyGTK] How to center text on multi-line buttons? Lomax 3 4,904 Jan-23-2021, 03:23 PM
Last Post: Lomax
  [PyQt] Python PyQt5 - Change label text dynamically based on user Input ppel123 1 14,595 Mar-20-2020, 07:21 AM
Last Post: deanhystad
  POPUP on widget Entry taratata2020 4 4,351 Mar-10-2020, 05:04 PM
Last Post: taratata2020
  [WxPython] How to show remove button at the right side of the hovering item of a combobox popup? indrajitmajumdar 0 2,769 Mar-28-2019, 11:24 AM
Last Post: indrajitmajumdar
  [Tkinter] [SOLVED] Create per button popup menu py2.7 AceScottie 5 6,805 May-31-2018, 12:39 AM
Last Post: AceScottie
  Set input text from button gio123 1 3,161 Mar-01-2018, 10:28 AM
Last Post: gio123
  popup message box code runs in Windows, but not in Linux Luke_Drillbrain 13 16,436 May-10-2017, 01:05 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

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