Python Forum
[Tkinter] How to make message box error stay on top of window
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] How to make message box error stay on top of window
#1
I have a program and when the error message pops up, it needs to stay on top of the current window. But when the error box pops up, the window minimizes. How to keep window from minimizing when message box pops up?

from tkinter import *
import tkinter as tk
from tkinter import ttk
import sqlite3
from tkinter import messagebox

def enterroom():
    enterroom = Toplevel()
    enterroom.title('Enter Room Inventory')
    enterroom.geometry("800x800+500+100")

    global entry1
    global my_box
    global mycombo

    label1=Label(enterroom, text="Room#")
    label1.place(x=10, y=10)
    entry1 = Entry(enterroom, width=10)
    entry1.place(x=70, y=10)

    options = [
        "Select Room Type",
        "NQ1 - Non Smoking Queen",
        "NQQ1 - Non Smoking Double Queen",
        "Q11 - Smoking Queen",
        "QQ1 - Smoking Double Queen",
        "NK1 - Non Smoking king",
        "K11 - Smoking King",
        "PNQ1 - Non Smoking Handi-Cap",
        "SK1 - Smoking Suit King",
        "SNK1 - Non Smoking Suite King",
    ]

    mycombo = ttk.Combobox(enterroom, width=40, value=options)
    mycombo.place(x=10, y=40)
    mycombo.current(0)

    my_box = Listbox(enterroom, height=30, width=30)
    my_box.place(x=500, y=20)
    boxlabel=Label(enterroom, text="Rooms Already Entered")
    boxlabel.place(x=500, y=0)

    conn = sqlite3.connect('roominventory.db')
    c = conn.cursor()
    c.execute("SELECT * FROM rooms")
    records = c.fetchall()

    for record in records:
        my_box.insert(END, record[0:1])

    conn.commit()
    conn.close()

    entry1.focus()

    btnenterroom = Button(enterroom, text="Enter Room", width=10, command=setroom)
    btnenterroom.place(x=10, y=70)



def setroom():
    global j
    conn = sqlite3.connect('roominventory.db')
    c = conn.cursor()
    c.execute("SELECT * FROM rooms")
    records = c.fetchall()

    for record in records:

        j=0
        j = int(entry1.get())
        if j==record[0]:
            showerror()
            break



    if j!=record[0]:
        jamin = mycombo.get()[0:4]
        jamin = jamin.strip()


        conn = sqlite3.connect('roominventory.db')
        c = conn.cursor()
        c.execute("INSERT INTO rooms VALUES (:number, :type, :rate, :vacant, :clean, :ooo, :r1, :r2, :r3, :r4, :r5)",

                      {
                          'number': entry1.get(),
                          'type': jamin,
                          'rate': 0,
                          'vacant': "Y",
                          'clean': "Y",
                          'ooo': "N",
                          'r1': "N",
                          'r2': "N",
                          'r3': "N",
                          'r4': "N",
                          'r5': 0,
                      }

                      )

        conn.commit()
        conn.close()

        my_box.delete(0, END)

        conn = sqlite3.connect('roominventory.db')
        c = conn.cursor()
        c.execute("SELECT * FROM rooms")
        records = c.fetchall()

        for record in records:
            my_box.insert(END, record[0:2])

        conn.commit()
        conn.close()

        mycombo.set("Select Room Type")

        entry1.delete(0, END)
        entry1.focus()

def showerror():
    messagebox.showwarning("Warning!", "You already entered this room#.")


root = Tk()
root.geometry("400x400")

btn1=Button(root, text="Click to enter room", command=enterroom)
btn1.pack()



root.mainloop()
Reply
#2
I figured it out. I used the parent statement as follows:

messagebox.showwarning("Warning!", "You already entered this room#.", parent=enterroom)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] [split] [split] How to make a window stay on top knoxvilles_joker 10 2,820 May-22-2021, 03:54 AM
Last Post: knoxvilles_joker
  Trying to make random image loop in Tk window using python Jediguy18 1 1,084 Dec-30-2020, 04:56 AM
Last Post: deanhystad
  Error message box and quit app Kumarkv 1 1,279 May-19-2020, 07:05 PM
Last Post: Larz60+
  tkinter window and turtle window error 1885 3 3,511 Nov-02-2019, 12:18 PM
Last Post: 1885
  [PyQt] No reaction and no error message when clicking button Atalanttore 4 2,665 Nov-23-2018, 01:48 PM
Last Post: Atalanttore
  Qt and QtPy Edit window & argument 1 has unexpected type 'Ui_MainWindow' Error Athul 6 13,533 Aug-20-2018, 02:09 PM
Last Post: Axel_Erfurt
  [PyQt] error message in pyqt pro red_man_008 8 5,133 Aug-13-2017, 08:50 PM
Last Post: red_man_008
  update a variable in parent window after closing its toplevel window gray 5 5,919 Mar-20-2017, 10:35 PM
Last Post: Larz60+
  [Tkinter] Make A Button That Opens Another Tk() Window That I Have Made Saif133 5 25,327 Jan-20-2017, 08:10 PM
Last Post: scriptso

Forum Jump:

User Panel Messages

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