用于 Python 2和 Python 3的 Tkinter / tkinter 的快速脚本。 **
我有一个脚本,其中有不同的 Python 2.* Tkinter 导入,所以浏览了 a 但我看到答案都是零散的。这里有一个小摘要,其中包含使用两个 Python 版本的安全脚本。
try: # Python 2.7
import Tkinter as tk
import tkColorChooser as color
import tkCommonDialog as cdialog
import Tkconstants as const
import Tkdnd as dnd
import tkFileDialog as fdialog
import tkFont as font
import tkMessageBox as msgbox
import ScrolledText as stext
import tkSimpleDialog as sdialog
import Tix as tix
import ttk
except ImportError: # Python 3.*
import tkinter as tk
from tkinter import (
colorchooser as color,
commondialog as cdialog,
constants as const,
dialog,
dnd,
filedialog as fdialog,
font,
messagebox as msgbox,
scrolledtext as stext,
simpledialog as sdialog,
tix,
ttk
)
ModuleNotFoundError 错误列表(运行 Python 3 时。)
ModuleNotFoundError: No module named 'Tkinter'
ModuleNotFoundError: No module named 'tkMessageBox'
ModuleNotFoundError: No module named 'ScrolledText'
ModuleNotFoundError: No module named 'tkFileDialog'