[GH-ISSUE #164] Message box does not open #153

Closed
opened 2026-02-26 12:20:39 +03:00 by kerem · 3 comments
Owner

Originally created by @Ferro1945 on GitHub (Apr 18, 2021).
Original GitHub issue: https://github.com/brentvollebregt/auto-py-to-exe/issues/164

My best thanks for this wonderful program! Using just pyinstaller I never managed to get a working .exe file, but with auto-py-to-exe I succeeded easily. Only one problem: I use a Message box in my Tkinter-based program. It does not open in .exe. Should I somehow tell to auto-py-to-exe about the Message box?

Originally created by @Ferro1945 on GitHub (Apr 18, 2021). Original GitHub issue: https://github.com/brentvollebregt/auto-py-to-exe/issues/164 My best thanks for this wonderful program! Using just pyinstaller I never managed to get a working .exe file, but with auto-py-to-exe I succeeded easily. Only one problem: I use a Message box in my Tkinter-based program. It does not open in .exe. Should I somehow tell to auto-py-to-exe about the Message box?
kerem closed this issue 2026-02-26 12:20:39 +03:00
Author
Owner

@brentvollebregt commented on GitHub (Apr 18, 2021):

Could you please provide a minimum working example of your issue?

<!-- gh-comment-id:822051449 --> @brentvollebregt commented on GitHub (Apr 18, 2021): Could you please provide a minimum working example of your issue?
Author
Owner

@Ferro1945 commented on GitHub (Apr 21, 2021):

Hi Brent,

and thanks for your rapid answer. Actually, I found the reason myself.
Using Thonny as my editor I wrote a short program with a message box.
When run in Thonny, the program worked all right. Then, I used
auto-py-to-exe to get the .exe file, and ran it. Again the same problem:
no message. Then it somehow came to my mind that perhaps I should run
the Python code in another editor. I took the program to VS Code, and
ran it. Now, after clicking the button to show the message I got an
error message: AttributeError: module 'tkinter' has no attribute
'messagebox'. I then found in internet that some other programmers had
got the same error message, and the reason is in Tkinter. One answer
told that

|"messagebox|, along with some other modules like |filedialog|, does not
automatically get imported when you |import tkinter|. Import it
explicitly, using |as| and/or |from| as desired."

When I added this import, VS Code no more gave any error message, and
the .exe file worked all right.

Anyway, I include the code for your information.

WBR,
Esko

Brent Vollebregt kirjoitti 18.4.2021 klo 22.59:

Could you please provide a minimum working example of your issue?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/brentvollebregt/auto-py-to-exe/issues/164#issuecomment-822051449,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ASIPDLPU2543M5BFYC7D43DTJM2Y3ANCNFSM43EOLWNQ.

Example program with MessageBox widget

Esko T. Rautanen 21.4.2021

import tkinter as tk
from tkinter import messagebox # This line had to be added.
class Example:

def __init__ (self, top):

    top.geometry ("300x100+100+100")
    
    self.MessButt = tk.Button (top)
    self.MessButt.place (x = 100, y = 30, height = 30, width = 100)
    self.MessButt.configure (text = "See message")
    self.MessButt.configure (command = self.MessBox)
    
def MessBox (self):
    self.Tiedot = tk.messagebox.showinfo ("Message", "Good news!\nThe message is displayed.")

root = tk.Tk ()
master = Example (root)
root.mainloop ()

<!-- gh-comment-id:824246775 --> @Ferro1945 commented on GitHub (Apr 21, 2021): Hi Brent, and thanks for your rapid answer. Actually, I found the reason myself. Using Thonny as my editor I wrote a short program with a message box. When run in Thonny, the program worked all right. Then, I used auto-py-to-exe to get the .exe file, and ran it. Again the same problem: no message. Then it somehow came to my mind that perhaps I should run the Python code in another editor. I took the program to VS Code, and ran it. Now, after clicking the button to show the message I got an error message: AttributeError: module 'tkinter' has no attribute 'messagebox'. I then found in internet that some other programmers had got the same error message, and the reason is in Tkinter. One answer told that |"messagebox|, along with some other modules like |filedialog|, does not automatically get imported when you |import tkinter|. Import it explicitly, using |as| and/or |from| as desired." When I added this import, VS Code no more gave any error message, and the .exe file worked all right. Anyway, I include the code for your information. WBR, Esko Brent Vollebregt kirjoitti 18.4.2021 klo 22.59: > > Could you please provide a minimum working example of your issue? > > — > You are receiving this because you authored the thread. > Reply to this email directly, view it on GitHub > <https://github.com/brentvollebregt/auto-py-to-exe/issues/164#issuecomment-822051449>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/ASIPDLPU2543M5BFYC7D43DTJM2Y3ANCNFSM43EOLWNQ>. > # Example program with MessageBox widget # Esko T. Rautanen 21.4.2021 import tkinter as tk from tkinter import messagebox # This line had to be added. class Example: def __init__ (self, top): top.geometry ("300x100+100+100") self.MessButt = tk.Button (top) self.MessButt.place (x = 100, y = 30, height = 30, width = 100) self.MessButt.configure (text = "See message") self.MessButt.configure (command = self.MessBox) def MessBox (self): self.Tiedot = tk.messagebox.showinfo ("Message", "Good news!\nThe message is displayed.") root = tk.Tk () master = Example (root) root.mainloop ()
Author
Owner

@brentvollebregt commented on GitHub (Apr 21, 2021):

Sounds like Thonny may have been importing some things that were appearing in your runtime.
Typically when a script does not run the same as an .exe compared to the packaged .py, I recommend double-clicking the .py script or use python <script.py> in cmd to run it as the exe would.

Glad you found a solution. I'll close this issue as I do not believe there is anything wrong anymore.

<!-- gh-comment-id:824323336 --> @brentvollebregt commented on GitHub (Apr 21, 2021): Sounds like Thonny may have been importing some things that were appearing in your runtime. Typically when a script does not run the same as an .exe compared to the packaged .py, I recommend double-clicking the .py script or use `python <script.py>` in cmd to run it as the exe would. Glad you found a solution. I'll close this issue as I do not believe there is anything wrong anymore.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/auto-py-to-exe#153
No description provided.