F Casian
F Casian

Reputation: 103

Tk-Inter messagebox secondary window error

First of all, thanks for stop by in my post. I'm a python amateur writer and I'm working in a GUI to capture some customer information, the first step is users make sure system is ON before they execute my application, for this, I use a messagebox.showinfo command.

However, this command also opens a secondary window (not sure why). Searching on internet, I realize that the best way to give ride of is with the instruction "withdraw".

my GUI should have a picture, which I use "Photoimage" for this but for some reason, the picture I'm trying to allocate into my GUI it goes to the secondary window open by messagebox.showinfo.

Does any one know why my picture ends on the secondary window and not in my main GUI?

the code below you can use in your computer you may need to create a folder in C and load a picture so you can see what I'm seeing here.

Thanks for stopping by.

from tkinter import *
import tkinter.messagebox
from tkinter import messagebox
import tkinter as tk
import os

################ To Avoid Parasite Window To Open ##################
##root = tkinter.Tk()
##root.withdraw()

messagebox.showinfo(message="Make sure System is ON", title="My App 1.00")

def configure():
   print ("hi")

####################### Main Window Design ##########################
##
#####################################################################
main = tkinter.Tk()
main.resizable(0,0)
main.geometry('490x510+700+50')
main.title('My App 1.00')
Label(main, text='GSYSTEM 1.00', font=("Tahoma", 20)).place(x=5,y=0)
LabelFrame(main, text=' Enter Data: ', font=("Tahoma", 14), height=180, width=480, bd=2, relief='ridge' ).place(x=5,y=100)

#########################  PN  ######################################
tmudir = "C:\\System"
os.chdir(tmudir)
Label(main, text='Scan Product :',font=("Tahoma", 12)).place(x=10,y=150)
LabelFrame(main, font=("Tahoma", 10), height=30, width=180, bd=3, relief='ridge').place(x=110,y=147)
pn_label = PhotoImage(file='TNL.png')
Label(image=pn_label).place(x=310,y=120)

####################### Main Window Design JO #######################
##
#####################################################################
LabelFrame(main, text='  ORDER INFO: ', font=("Tahoma", 14), height=100, width=480, bd=2,   relief='ridge' ).place(x=5,y=360)
Label(main, text='Scan   Order:',font=("Tahoma", 12)).place(x=10,y=385)
joborderinfo = Entry(main,font=("Arial Narrow", 12))
joborderinfo.place(x=265,y=385)

########## Main Window Design Buttons Start and Config ##############
##
#####################################################################
power_supply_btn = Button(main, text="START TEST", font=("Tahoma", 21), height=1, width=24, command=configure)
power_supply_btn.place(x=55,y=40)
power_supply_btn.config(state=NORMAL)

mainloop()
SystemExit()

Upvotes: 0

Views: 59

Answers (1)

Novel
Novel

Reputation: 13729

You have to create the main window first, and thee use withdraw() to show only the message. You would do it like this:

import tkinter as tk
from tkinter import messagebox

main = tk.Tk()
main.withdraw()

messagebox.showinfo(message="Make sure System is ON", title="My App 1.00")

main.deiconify() # undo the withdraw() command.

def configure():
   print ("hi")

main.resizable(0,0)
main.geometry('490x510+700+50')
main.title('My App 1.00')
# rest of your code

Upvotes: 1

Related Questions