4

I have a tiny button with a question mark in my app. When clicked, it displays the doc string from a function in my app which helps to explain what the app does.

The problem is, I build a single .exe using pyinstaller and this question mark button does nothing when clicked.

Recreation Steps

  1. save the file below as run.py
  2. open command-prompt
  3. paste pyinstaller.exe --onefile --windowed run.py
  4. go to dist folder and run single exe
  5. click ? button and notice it does nothing

run.py below

import tkinter as tk
from tkinter import ttk

''' pyinstaller.exe --onefile --windowed run.py '''

def someotherfunction():
  '''
  This is some message that I
  want to appear but it currently doesn\'t
  seem to work

  when I put try to launch a messagebox
  showinfo window...
  '''
  pass

def showhelpwindow():
  return tk.messagebox.showinfo(title='How to use this tool',
                         message=someotherfunction.__doc__)

root = tk.Tk()
helpbutton = ttk.Button(root, text='?', command=showhelpwindow, width=2)
helpbutton.grid(row=0, column=3, sticky='e')
root.mainloop()

My setup:

  • PyInstaller 3.2
  • Windows 7
  • Python 3.4.2

I tried adding --noupx option but that didn't fix it.

EDIT:

I removed --windowed option this time and the console is now showing me an error when I click this button.

Exception in Tkinter callback
Traceback (most recent call last):
  File "tkinter\__init__.py", line 1533, in __call__
  File "run.py", line 156, in showhelpwindow
AttributeError: 'module' object has no attribute 'messagebox'
Community
  • 1
  • 1
Jarad
  • 17,409
  • 19
  • 95
  • 154
  • 2
    If you remove the `--windowed` option and run the .exe file from the command line, does it produce an error when you click the button? I would do that myself, but I don't have Python 3 installed at the moment. – Repiklis Oct 05 '16 at 09:12
  • @Repiklis Thanks for your help! I did as you suggested and it revealed the problem. I needed to import the messagebox module with an import statement. I'll post my working solution below. – Jarad Oct 05 '16 at 14:58

1 Answers1

2

Line 3 below is the solution. I needed to import the tkinter.messagebox module explicitly.

import tkinter as tk
from tkinter import ttk
import tkinter.messagebox

''' pyinstaller.exe --onefile --windowed run.py '''

def someotherfunction():
  '''
  This is some message that I
  want to appear but it currently doesn\'t
  seem to work

  when I put try to launch a messagebox
  showinfo window...
  '''
  pass

def showhelpwindow():
  return tk.messagebox.showinfo(title='How to use this tool',
                         message=someotherfunction.__doc__)

root = tk.Tk()
helpbutton = ttk.Button(root, text='?', command=showhelpwindow, width=2)
helpbutton.grid(row=0, column=3, sticky='e')
root.mainloop()
Jarad
  • 17,409
  • 19
  • 95
  • 154