[英]Python Tkinter/GUI import Error
我在頁面 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 行,在 import _support ModuleNotFoundError: No module named '_support '
您沒有安裝模塊 _support 並且縮進到處都是。
看起來您可能已經使用 PAGE(或其他 GUI 生成器)為您的 GUI 生成 Python 代碼,是嗎?
當您使用生成器並創建包含您可能擁有或可能沒有的庫的代碼時,很難追蹤這樣的東西。
幸運的是,在這種情況下(如果您至少使用 PAGE),有問題的庫也是由 PAGE 生成的。
您需要轉到 Gen_Python 菜單,不僅選擇“生成 Python GUI”項,還要選擇“生成支持模塊”項以生成它嘗試使用“_support”導入的庫。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.