我在页面gui中创建了简单的计算器然后我复制该代码并在python 3.6.3中运行它但是它给了我这个错误
import sys
try:
from Tkinter import *
except ImportError:
from tkinter import *
try:
import ttk
py3 = False
except ImportError:
import tkinter.ttk as ttk
py3 = True
import _support
def vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = Tk()
top = Simple_Calculator (root)
_support.init(root, top)
root.mainloop()
w = None
def create_Simple_Calculator(root, *args, **kwargs):
'''Starting point when module is imported by another program.'''
global w, w_win, rt
rt = root
w = Toplevel (root)
top = Simple_Calculator (w)
_support.init(w, top, *args, **kwargs)
return (w, top)
def destroy_Simple_Calculator():
global w
w.destroy()
w = None
class Simple_Calculator:
def __init__(self, top=None):
'''This class configures and populates the toplevel window.
top is the toplevel containing window.'''
_bgcolor = '#d9d9d9' # X11 color: 'gray85'
_fgcolor = '#000000' # X11 color: 'black'
_compcolor = '#d9d9d9' # X11 color: 'gray85'
_ana1color = '#d9d9d9' # X11 color: 'gray85'
_ana2color = '#d9d9d9' # X11 color: 'gray85'
top.geometry("346x238+495+156")
top.title("Simple Calculator")
top.configure(background="#d9d9d9")
self.but40 = Button(top)
self.but40.place(relx=0.14, rely=0.38, height=24, width=67)
self.but40.configure(activebackground="#d9d9d9")
self.but40.configure(activeforeground="#000000")
self.but40.configure(background="#7d83d8")
self.but40.configure(disabledforeground="#a3a3a3")
self.but40.configure(foreground="#000000")
self.but40.configure(highlightbackground="#d9d9d9")
self.but40.configure(highlightcolor="black")
self.but40.configure(pady="0")
self.but40.configure(text='''Add''')
self.but40.configure(width=67)
self.but41 = Button(top)
self.but41.place(relx=0.38, rely=0.38, height=24, width=67)
self.but41.configure(activebackground="#d9d9d9")
self.but41.configure(activeforeground="#000000")
self.but41.configure(background="#7d83d8")
self.but41.configure(disabledforeground="#a3a3a3")
self.but41.configure(foreground="#000000")
self.but41.configure(highlightbackground="#d9d9d9")
self.but41.configure(highlightcolor="black")
self.but41.configure(pady="0")
self.but41.configure(text='''Sub''')
self.but42 = Button(top)
self.but42.place(relx=0.14, rely=0.55, height=24, width=67)
self.but42.configure(activebackground="#d9d9d9")
self.but42.configure(activeforeground="#000000")
self.but42.configure(background="#7d83d8")
self.but42.configure(disabledforeground="#a3a3a3")
self.but42.configure(foreground="#000000")
self.but42.configure(highlightbackground="#d9d9d9")
self.but42.configure(highlightcolor="black")
self.but42.configure(pady="0")
self.but42.configure(text='''Multiply''')
self.but43 = Button(top)
self.but43.place(relx=0.38, rely=0.55, height=24, width=67)
self.but43.configure(activebackground="#d9d9d9")
self.but43.configure(activeforeground="#000000")
self.but43.configure(background="#7d83d8")
self.but43.configure(disabledforeground="#a3a3a3")
self.but43.configure(foreground="#000000")
self.but43.configure(highlightbackground="#d9d9d9")
self.but43.configure(highlightcolor="black")
self.but43.configure(pady="0")
self.but43.configure(text='''Divide''')
self.but43.configure(width=67)
self.Button2 = Button(top)
self.Button2.place(relx=0.72, rely=0.71, height=24, width=49)
self.Button2.configure(activebackground="#d9d9d9")
self.Button2.configure(activeforeground="#000000")
self.Button2.configure(background="#9a63d8")
self.Button2.configure(disabledforeground="#a3a3a3")
self.Button2.configure(foreground="#000000")
self.Button2.configure(highlightbackground="#d9d9d9")
self.Button2.configure(highlightcolor="black")
self.Button2.configure(pady="0")
self.Button2.configure(text='''Display''')
self.Entry1 = Entry(top)
self.Entry1.place(relx=0.12, rely=0.13,height=30, relwidth=0.47)
self.Entry1.configure(background="#a6c1ff")
self.Entry1.configure(disabledforeground="#a3a3a3")
self.Entry1.configure(font="TkFixedFont")
self.Entry1.configure(foreground="#000000")
self.Entry1.configure(insertbackground="black")
self.Entry1.configure(width=164)
if __name__ == '__main__':
vp_start_gui()
追踪(最近一次通话): 文件“C:/ Users / Zeeshan Khalid / AppData / Local / Programs / Python / Python36-32 / tkinter initial chec.py”,第22行,in import _support ModuleNotFoundError:没有名为'_support'的模块
答案 0 :(得分:0)
您没有安装模块_support,并且缩进遍布。
答案 1 :(得分:0)
您似乎已经使用PAGE(或其他GUI生成器)为GUI生成了Python代码,是吗?
在使用生成器时,很难找到这样的东西,并且它会创建代码,其中包含可能包含或可能不包含的库。
在这种情况下(至少如果您使用PAGE,则很幸运)相关的库也由PAGE生成。
您需要转到Gen_Python菜单,不仅要选择“ Generate Python GUI”(生成Python GUI)项,还需要选择“ Generate Support Module”(生成支持模块)项以生成要通过“ _support”导入的库。