微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Tkinter回调和追溯记录和Jupyter Notebook问题

如何解决Tkinter回调和追溯记录和Jupyter Notebook问题

所以下面是一个使用Tkinter的GUI界面,在这里我试图在按下按钮后调用基本功能,问题是当我在Jupyter Notebook中执行此功能时,程序可以正常工作。 但是当我尝试以脚本(.py)文件形式运行时,它在命令外壳中给出了错误

查询1-以下如何解决此问题,因为我无法找出错误,我想我没有在此处传递参数?

查询2-为什么在Jupyter Notebook中没有错误出现而在Python Shell中没有发生错误

我正在使用Python 2.7

注意:-我面对NumPy在3.7和3.8中没有导入错误,因此我不得不切换到较低版本的python来解决此问题(无法卸载并安装NumPy,因为它是办公室笔记本电脑,没有管理员权限)

Python Shell错误

error received
2402:8100:5::1600
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda2\lib\lib-tk\Tkinter.py",line 1541,in __call__
    return self.func(*args)
  File "D:\Papa\Python\IPV6_Final_V2.py",line 585,in excel_import
    import_exl()
  File "D:\Papa\Python\IPV6_Final_V2.py",line 475,in import_exl
    XML_Print()
  File "D:\Papa\Python\IPV6_Final_V2.py",line 27,in XML_Print
    mytree.write( export_dir +"/"+ str(MRBTS) +'_IPV6.xml',encoding='UTF-8')
NameError: global name 'export_dir' is not defined

代码

from Tkinter import *
import tkFileDialog as filedialog
#from Tkinter import filedialog
import tkMessageBox as messageBox
#from Tkinter import messageBox

Regen=Tk()
#Title for the window
Regen.title("VIL Regen Tool")

#Color Backgroud for the window

Regen.configure(bg="grey")

#Geometry for the window (300x300 defines the size + value defines the position in x and y axis)

Regen.geometry("300x300+500+200")

#Labeling
mylabel1=Label(text="VIL Regen Tool",fg="orange",bg="grey",font="Times 15 bold").pack()
mylabel1=Label(text="Developed by Sushanto Banerjee",font="Times 15 bold").place(x=10,y=100)

def xml_import():
    global xml_file
    xml_file=filedialog.askopenfile(filetypes=[("XML files","*.xml")])
    label1=Label(text="XML Backup Imported").place(x=100,y=240)
    import_xml()
def excel_import():
    global excel_file
    excel_file=filedialog.askopenfilename(filetypes=[("Excel files","*.xlsx")])
    label2=Label(text="IP Plan Imported").place(x=120,y=270)
    import_exl()
def export():
    global export_dir
    export_dir=filedialog.askdirectory()
    mess=messageBox.showinfo(title="XML Generated",message="XMl generated")
    command=Regen.destroy()
    
button=Button(text="Import XML Backup",width=30,command=xml_import).pack()
button=Button(text="Import Excel IP Plan",command=excel_import).pack()
button=Button(text="Generate",command=export).pack()

Regen.mainloop()


def XML_Print():
    
    # Replacing the Vlues with IPV6 and writing it in XML


    for child in myroot.findall('.//{raml21.xsd}p'):
        parameter=child.attrib
        values=child.text
        for key in parameter:
    #Replacing GTPU IP
            if parameter[key]=="sgwIpAddress":
                new_values={'sgwIpAddress':'2402:8100:5::1600'}

                for key in new_values:
                    child.text=new_values['sgwIpAddress']
                    print (child.text)
    #                mytree.write('C:\output.xml',encoding='UTF-8')

                    mytree.write( export_dir +"/"+ str(MRBTS) +'_IPV6.xml',encoding='UTF-8')

我正在使用Python 2.7

注意:-我正面临NumPy在3.7和3.8版本中未导入错误的问题,因此我不得不切换到较低版本的python来解决此问题(无法卸载并安装NumPy,因为它是办公室笔记本电脑,带有没有管理员权限)

下面的数字导入错误

>>> import numpy
C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py:140: UserWarning: mkl-service package Failed to import,therefore Intel(R) MKL initialization ensuring its correct out-of-the Box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package,see http://github.com/Intelpython/mkl-service
  from . import _distributor_init
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\__init__.py",line 24,in <module>
    from . import multiarray
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\multiarray.py",line 14,in <module>
    from . import overrides
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\overrides.py",line 7,in <module>
    from numpy.core._multiarray_umath import (
ImportError: DLL load Failed: The specified module Could not be found.

During handling of the above exception,another exception occurred:

Traceback (most recent call last):
  File "<stdin>",line 1,in <module>
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py",line 142,in <module>
    from . import core
  File "C:\ProgramData\Anaconda3\lib\site-packages\numpy\core\__init__.py",line 54,in <module>
    raise ImportError(msg)
ImportError:

IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!

Importing the numpy c-extensions Failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that,then:
  1. Check that you expected to use python3.7 from "C:\ProgramData\Anaconda3\python.exe",and that you have no directories in your PATH or PYTHONPATH that can
     interfere with the Python and numpy version "1.18.1" you're trying to use.
  2. If (1) looks fine,you can open a new issue at
     https://github.com/numpy/numpy/issues.  Please include details on:
     - how you installed Python
     - how you installed numpy
     - your operating system
     - whether or not you have multiple versions of Python installed
     - if you built from source,your compiler versions and ideally a build log

- If you're working with a numpy git repository,try `git clean -xdf`
  (removes all files not under version control) and rebuild numpy.

Note: this error has many possible causes,so please don't comment on
an existing issue about this - open a new one instead.

Original error was: DLL load Failed: The specified module Could not be found.

Numpy安装确认

(base) PS C:\Users\Sushanto.Banerjee> pip show numpy
Name: numpy
Version: 1.18.1
Summary: NumPy is the fundamental package for array computing with Python.
Home-page: https://www.numpy.org
Author: Travis E. Oliphant et al.
Author-email: None
License: BSD
Location: c:\programdata\anaconda3\lib\site-packages
Requires:
required-by: tables,statsmodels,seaborn,scipy,scikit-learn,PyWavelets,pytest-arraydiff,patsy,pandas,numexpr,numba,mkl-random,mkl-fft,matplotlib,imageio,h5py,Bottleneck,bokeh,bkcharts,astropy
(base) PS C:\Users\Sushanto.Banerjee>

解决方法

好的,所以当您指出错误所在的行后,我对其进行了追溯,并发现我正在调用的函数具有一些引起问题的因变量 下面是我最终的结果,谢谢

#from Tkinter import *
import tkFileDialog as filedialog
#from Tkinter import filedialog
import tkMessageBox as messagebox
#from Tkinter import messagebox

Regen=Tk()
#Title for the window
Regen.title("VIL Regen Tool")

#Color Backgroud for the window

Regen.configure(bg="grey")

#Geometry for the window (300x300 defines the size + value defines the position in x and y axis)

Regen.geometry("300x300+500+200")

#Labeling
mylabel1=Label(text="VIL Regen Tool",fg="orange",bg="grey",font="Times 15 bold").pack()
mylabel1=Label(text="Developed by Sushanto Banerjee",font="Times 15 bold").place(x=10,y=100)

def xml_import():
    global xml_file
    xml_file=filedialog.askopenfile(filetypes=[("XML files","*.xml")])
    label1=Label(text="XML Backup Imported").place(x=100,y=240)
    import_xml()
def excel_import():
    global excel_file
    excel_file=filedialog.askopenfilename(filetypes=[("Excel files","*.xlsx")])
    label2=Label(text="IP Plan Imported").place(x=120,y=270)
    import_exl()
def export():
    global export_dir
    export_dir=filedialog.askdirectory()
    mess=messagebox.showinfo(title="XML Generated",message="XMl generated")
    XML_Print()
    command=Regen.destroy()

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。