cx_freeze error with tkinter library treectrl converting to exe setup

无人久伴 提交于 2021-01-28 04:23:09

问题


I am using python version 3.7 , I used this external library named treectrl and it works perfectly fine when I run my .py file but when I converted into exe file using cx_freeze it is giving me error NomodulleFound named tkinter. I have tried other small programs which does not use this library and I converted them in to exe file they work perfectly fine. So the idea which I got is that there is problem with this library. So I can't figure out what part this. I provided all codes , all downnload links and also error which I am getting.

https://sourceforge.net/projects/tkintertreectrl/files/

https://sourceforge.net/projects/tktreectrl/files/

Here is my code which I am converting python to exe

######################################################################



import tkinter


from TkTreectrl import *

# define some data to insert into the list:
data = {
    'Joe':      1000.00,
    'Jill':     738.39,
    'Jack':     625.11,
    'Jane':     99.99
}

root = tkinter.Tk()
# create list with scrollbars
slistbox = ScrolledMultiListbox(root)
slistbox.pack(fill='both', expand=1)
listbox = slistbox.listbox
# create columns
listbox.configure(columns=('Paid', 'Customer', 'Debt'))

#### add checkbox support to the listbox ####
# checkbox icons:
checked = tkinter.PhotoImage(data=('R0lGODlhDQANABEAACwAAAAADQANAIEAAAB/f3/f3'
    '9////8CJ4yPNgHtLxYYtNbIbJ146jZ0gzeCIuhQ53NJVNpmryZqsYDnemT3BQA7'))
unchecked = tkinter.PhotoImage(data=('R0lGODlhDQANABEAACwAAAAADQANAIEAAAB/f3'
    '/f39////8CIYyPNgHtLxYYtNbIrMZTX+l9WThwZAmSppqGmADHcnRaBQA7'))

# create treectrl state, element and style for the checkboxes:
listbox.state_define('Checked')
imgCheck = listbox.element_create(
            type='image', image=(checked, 'Checked', unchecked, ()))

icon_style = listbox.style_create()
listbox.style_elements(icon_style,
            listbox.element('select'), imgCheck, listbox.element('text'))
listbox.style_layout(icon_style, imgCheck, padx=3, pady=2)
listbox.style(0, icon_style)


# define checkbox callback that will be bound to mouse-button-1 events:
def cmd(event):
    # check which element was clicked
    identify = listbox.identify(event.x, event.y)
    # identify might be None or look like:
    # ('item', '2', 'column', '0') or
    # ('item', '3', 'column', '0', 'elem', 'pyelement3')
    if identify:
        try:
            item, column, element = identify[1], identify[3], identify[5]
            if element == imgCheck:
                # toggle the "checked" state
                listbox.itemstate_forcolumn(item, column, '~Checked')
                # do something, dependent on the current state of the checkbox
                new = listbox.itemstate_forcolumn(item, column)
                if new and 'Checked' in new:
                    # the checkbox was newly checked
                    print('Checked item', item, 'in column', column)
                    # example: debts are paid, set "Debt" to 0.00
                    listbox.itemelement_configure(item, listbox.column(2),
                                    listbox.element('text'), text='0.00')
                else:
                    # example: no payment received, set debt to stored value
                    print('Unchecked item', item, 'in column', column)
                    customer = listbox.itemelement_cget(
                                    item, listbox.column(1),
                                    listbox.element('text'), 'text')
                    debt = data[customer]
                    listbox.itemelement_configure(item, listbox.column(2),
                                    listbox.element('text'), text=debt)
        except IndexError:
            # we did not hit the checkbox, never mind
            pass

# bind the callback to button 1 events
listbox.bind('<1>', cmd)

# insert data into the list to see if this works:
for customer in data:
    listbox.insert('end', '', customer, data[customer])


root.mainloop()

Here is my setup.py file

import cx_Freeze
import sys
import os
base = None

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

os.environ['TCL_LIBRARY'] = r"C:\Users\osama shakeel\AppData\Local\Programs\Python\Python37-32\tcl\tcl8.6"
os.environ['TK_LIBRARY'] = r"C:\Users\osama shakeel\AppData\Local\Programs\Python\Python37-32\tcl\tk8.6"

executables = [cx_Freeze.Executable("working.py", base=base, icon="icon.ico")]


cx_Freeze.setup(
    name = "test",
    options = {"build_exe": {"packages":["tkinter","os"], "include_files":["icon.ico",'tcl86t.dll','tk86t.dll']}},
    version = "0.01",
    description = "Tkinter Application",
    executables = executables
    )

here is my error

cx_Freeze: Python error in main script
Traceback (most recent call last):
File "C:\Users\osama
shakeel AppData\Local\Programs\Python Python37-32\lib \site
-packages\cx_Freeze\initscripts _startup_.py", line 40, in run
module.runo
File "C:\Users\osama
shakeel AppData\Local\Programs\Python Python37-32\lib\site
-packages\cx_Freeze\initscripts\Console.py", line 37, in run
exec(code, [name__ main__'})
File "working.py", line 5, in <module>
ModuleNotFoundError: No module named 'tkinter
ок

来源:https://stackoverflow.com/questions/61015846/cx-freeze-error-with-tkinter-library-treectrl-converting-to-exe-setup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!