我有一个需要pymysql库的Python程序,但是当我打开.py文件时,它在尝试执行时立即崩溃
import pymysql
我无法读取任何错误消息,因为窗口关闭得太快,奇怪的是当我在Pycharm中运行代码时它工作得很好! 关于如何解决这个问题的任何想法?
- 编辑 -
我已经通过命令提示符运行程序,现在它可以很好地导入模块,但是给出了错误"无法从文件加载图像"。再说一次,当我在Pycharm上运行它时,它的工作原理非常好。这是完整的代码:
import pymysql
import wx
import wx.grid
import os
import sys
image_name = 'logo.bmp'
if getattr(sys, 'frozen', False):
application_path = os.path.dirname(sys.executable)
elif __file__:
application_path = os.path.dirname(__file__)
image_path = str(application_path) + '/' + image_name
class mainWindow(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, size=(380, 210), title='Venetex Database Manager',
style=wx.MINIMIZE_BOX | wx.CLOSE_BOX | wx.CAPTION,
*args, **kwargs)
self.Centre()
self.mainGUI()
self.Show(True)
self.Bind(wx.EVT_CLOSE, self.OnCloseFrame)
def mainGUI(self):
panel = wx.Panel(self)
image = wx.Bitmap(image_path)
wx.StaticBitmap(panel, -1, image, (10, 10), (image.GetWidth(), image.GetHeight()))
visualizza_button = wx.Button(panel, id=wx.ID_ANY, label='Visualizza Dati',
pos=(200, 10 + 40))
visualizza_button.SetSize((150, 25))
modifica_button = wx.Button(panel, id=wx.ID_ANY, label='Modifica/Inserisci Dati',
pos=(200, 10 + image.GetHeight() - 65))
modifica_button.SetSize((150, 25))
visualizza_button.Bind(wx.EVT_BUTTON, self.visualizza)
def OnCloseFrame(self, event):
dialog = wx.MessageDialog(self, message="Sei sicuro di voler uscire?", caption="Conferma uscita",
style=wx.YES_NO,
pos=wx.DefaultPosition)
dialog.Show(True)
response = dialog.ShowModal()
if response == wx.ID_YES:
self.Destroy()
else:
event.StopPropagation()
def visualizza(self, event):
pass
def main():
app = wx.App()
mainWindow(None)
app.MainLoop()
main()
sys.exit()