AttributeError:'module'对象没有属性'window
好的,我看到很多帖子讨论类似的问题,但没有一个完全符合我的情况。
这是软件的规格:
Python 3.3(有多个版本,一个在Windows XP 32位上,另一个在Windows 7 64位上)
两个版本都出现了同样的问题
在这两台机器上都有win32 API供Python使用
这是代码:
#Training Program for Chemence Owned Laser Cutter
#Written by Jared Lunt in the Python Programming Language.
try:
import tkinter
except ImportError:
raise ImportError ("The tkinter Module is required to run this program.")
main = tkinter.Tk()
#The first objective of the app design is to state the Title
main.title("Laser Cutter Operations Training")
#The second objective of the app design is to define the size of the Main Window.
import sys, cmd
sys.path.append('C:/Python33//Lib/site-packages/win32')
from win32api import GetSystemMetrics
systemWidth = GetSystemMetrics (0)
systemHeight = GetSystemMetrics (1)
width = systemWidth / 2
height = systemHeight / 2
left = width / 2
top = height / 2
window = cmd.window()
cmd.ShowWindow(window)
cmd.window(window, edit=True, topLeftCorner=( top, left ), widthHeight=( width, height ) )
main.mainloop()'
1 个回答
1
你在这里尝试的事情有点奇怪。我想知道你是从哪里想到要导入cmds或cmd的,不过无论如何,这不是正确的做法。
你可以直接使用Tkinter的geometry方法来控制窗口的大小和位置:
main.geometry("%sx%s+%s+%s" % (width, height, left, top) )
而不是使用那些涉及cmd
的代码。