0
import sys
from cx_Freeze import setup, Executable

build_exe_options = {'packages': ['os','tkinter','random',
                              'heapq','collections','sys','pickle']}

base = None
if sys.platform == "win32":
    base = "Win32GUI"

setup(  name = 'Game',
        version = '0.02',
        description = 'My GUI application!',
        options = {'build_exe': build_exe_options},
        executables = [Executable('Game.py', base=base)])

here's the code of the setup

from tkinter import *
value_a = 'hahaha'
a =messagebox.showinfo('laugh',value_a)

and the code that would executed

the erorr is Nameerorr : name "messagebox" is not defined when I typed python 123.py build or python haha.py build in cmd

I already used import *, if I run the code it shows message but neither in cmd nor .exe

Should I use import tkinter as tk? But it is difficult to read my code by adding "tk", I want to keep import * so that no "tk.xxx" is needed and it will still works on exe.

Montague27
  • 81
  • 10

2 Answers2

0

from tkinter import * does not work for messagebox, so you must import the message box individually like below

from tkinter import messagebox
pacholik
  • 8,607
  • 9
  • 43
  • 55
Meku
  • 17
  • 1
0

I had this problem too. It worked OK in the IDE but not in direct run mode. Adding import tkinter.messagebox as messagebox fixed the problem. Thanks, G.

Luca
  • 9,259
  • 5
  • 46
  • 59