我目前正在尝试让 Python 使用 Subprocess 从 D:/My Games 运行 .exe。目的很简单,只要运行选中的游戏即可。我现在使用的代码在我尝试访问我的 C: 驱动器时有效,但在尝试访问我的 D: 驱动器时出现错误。“错误表超出范围”是我得到的错误。任何人都知道如何能够从 Python 中访问此驱动器?
import wx
import subprocess
import os
GamesList=(os.listdir('D:\\My Games\\'))
for item in GamesList:
if str(item) == 'desktop.ini':
GamesList.remove(item)
class MainMenu(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,"Games List", size=(550,400))
panel=wx.Panel(self)
GameBox = wx.ListBox(panel, -1,(407,5),(122,350),GamesList,wx.LB_SINGLE)
GameBox.Bind(wx.EVT_LISTBOX, OnGameSelection)
def OnGameSelection(Event):
GameBox = Event.GetEventObject()
GameIndex = GameBox.GetSelection()
SelGame = GamesList[GameIndex]
subprocess.call(['D:\\My Games\\'+ SelGame + '\\' + SelGame + '.exe'])
if __name__=='__main__':
app=wx.PySimpleApp()
frame=MainMenu(parent=None,id=-1)
frame.Show()
app.MainLoop()