今天我写了一个代码,无法执行,希望大家帮帮我,系统是 win10,目的:整蛊朋友

import wx
class MyFarm(wx.Frame):
    def __int__(self,parent,id):
        wx.Frame.__int__(self,parent,id,title="滑稽",
                            pos=(0,0),size=(1366,768))
        panel=wx.Panel(self)
        title=wx.StaticText(panel,label='看来你还真点了',pos=(100,20))
        font=wx.Font(16,wx.default,wx.FONTSTYLE_NORMAL,wx.NORMAL)
        wx.StaticText(panel,label="滑稽",pos=(50,50))
        wx.StaticText(panel,label="滑稽",pos=(50,70))
        wx.StaticText(panel,label="滑稽",pos=(50,90))
        wx.StaticText(panel,label="滑稽",pos=(50,110))
        wx.StaticText(panel,label="滑稽",pos=(50,130))
        wx.StaticText(panel,label="滑稽",pos=(50,170))
        wx.StaticText(panel,label="滑稽",pos=(50,190))
        wx.StaticText(panel,label="滑稽",pos=(50,210))
        wx.StaticText(panel,label="滑稽",pos=(50,230))
        wx.StaticText(panel,label="滑稽",pos=(50,250))
        wx.StaticText(panel,label="滑稽",pos=(50,280))
        wx.StaticText(panel,label="滑稽",pos=(50,310))
        wx.StaticText(panel,label="滑稽",pos=(50,330))
        wx.StaticText(panel,label="滑稽",pos=(50,350))
        wx.StaticText(panel,label="滑稽",pos=(50,370))
        wx.StaticText(panel,label="滑稽",pos=(50,390))
        wx.StaticText(panel,label="滑稽",pos=(50,410))
        wx.StaticText(panel,label="滑稽",pos=(50,430))
        wx.StaticText(panel,label="滑稽",pos=(50,450))
        wx.StaticText(panel,label="滑稽",pos=(50,470))

        if __name__=='__main__':
            app=wx.App()
            frame=MyFarm(parent=None,id=1)
            frame.Show()
            app.MainLoop()
最佳答案

if判断句放错位置了
正确代码:

import wx
class MyFarm(wx.Frame):
    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id,title="滑稽",
                            pos=(0,0),size=(1366,768))
        panel=wx.Panel(self)
        title=wx.StaticText(panel,label='看来你还真点了',pos=(100,20))
        font=wx.Font(16,wx.default,wx.FONTSTYLE_NORMAL,wx.NORMAL)
        wx.StaticText(panel,label="滑稽",pos=(50,50))
        wx.StaticText(panel,label="滑稽",pos=(50,70))
        wx.StaticText(panel,label="滑稽",pos=(50,90))
        wx.StaticText(panel,label="滑稽",pos=(50,110))
        wx.StaticText(panel,label="滑稽",pos=(50,130))
        wx.StaticText(panel,label="滑稽",pos=(50,170))
        wx.StaticText(panel,label="滑稽",pos=(50,190))
        wx.StaticText(panel,label="滑稽",pos=(50,210))
        wx.StaticText(panel,label="滑稽",pos=(50,230))
        wx.StaticText(panel,label="滑稽",pos=(50,250))
        wx.StaticText(panel,label="滑稽",pos=(50,280))
        wx.StaticText(panel,label="滑稽",pos=(50,310))
        wx.StaticText(panel,label="滑稽",pos=(50,330))
        wx.StaticText(panel,label="滑稽",pos=(50,350))
        wx.StaticText(panel,label="滑稽",pos=(50,370))
        wx.StaticText(panel,label="滑稽",pos=(50,390))
        wx.StaticText(panel,label="滑稽",pos=(50,410))
        wx.StaticText(panel,label="滑稽",pos=(50,430))
        wx.StaticText(panel,label="滑稽",pos=(50,450))
        wx.StaticText(panel,label="滑稽",pos=(50,470))
if __name__=='__main__':
    app=wx.App()
    frame=MyFarm(parent=None,id=1)
    frame.Show()
    app.MainLoop()
3年前 评论
acup (楼主) 3年前
Coolest (作者) 3年前
acup (楼主) 3年前
acup (楼主) 3年前
Coolest (作者) 3年前
acup (楼主) 3年前
讨论数量: 3

if判断句放错位置了
正确代码:

import wx
class MyFarm(wx.Frame):
    def __init__(self,parent,id):
        wx.Frame.__init__(self,parent,id,title="滑稽",
                            pos=(0,0),size=(1366,768))
        panel=wx.Panel(self)
        title=wx.StaticText(panel,label='看来你还真点了',pos=(100,20))
        font=wx.Font(16,wx.default,wx.FONTSTYLE_NORMAL,wx.NORMAL)
        wx.StaticText(panel,label="滑稽",pos=(50,50))
        wx.StaticText(panel,label="滑稽",pos=(50,70))
        wx.StaticText(panel,label="滑稽",pos=(50,90))
        wx.StaticText(panel,label="滑稽",pos=(50,110))
        wx.StaticText(panel,label="滑稽",pos=(50,130))
        wx.StaticText(panel,label="滑稽",pos=(50,170))
        wx.StaticText(panel,label="滑稽",pos=(50,190))
        wx.StaticText(panel,label="滑稽",pos=(50,210))
        wx.StaticText(panel,label="滑稽",pos=(50,230))
        wx.StaticText(panel,label="滑稽",pos=(50,250))
        wx.StaticText(panel,label="滑稽",pos=(50,280))
        wx.StaticText(panel,label="滑稽",pos=(50,310))
        wx.StaticText(panel,label="滑稽",pos=(50,330))
        wx.StaticText(panel,label="滑稽",pos=(50,350))
        wx.StaticText(panel,label="滑稽",pos=(50,370))
        wx.StaticText(panel,label="滑稽",pos=(50,390))
        wx.StaticText(panel,label="滑稽",pos=(50,410))
        wx.StaticText(panel,label="滑稽",pos=(50,430))
        wx.StaticText(panel,label="滑稽",pos=(50,450))
        wx.StaticText(panel,label="滑稽",pos=(50,470))
if __name__=='__main__':
    app=wx.App()
    frame=MyFarm(parent=None,id=1)
    frame.Show()
    app.MainLoop()
3年前 评论
acup (楼主) 3年前
Coolest (作者) 3年前
acup (楼主) 3年前
acup (楼主) 3年前
Coolest (作者) 3年前
acup (楼主) 3年前

我认为,你应该补充几点信息,才能获得你想要的答案:

  1. 合适的问题描述,把你遇到的问题,尝试的方法,都列举出来;

  2. 执行代码的环境,是 Win10、Mac 还是 Linux 中的一种;

  3. 你执行这段代码的目的是什么。

3年前 评论
Coolest 3年前
Jason990420

几个错误的地方

  1. 这一段代码缩格错误
        if __name__=='__main__':
            app=wx.App()
            frame=MyFarm(parent=None,id=1)
            frame.Show()
            app.MainLoop()
  1. 两个__init__都打错
    def __int__(self,parent,id):
        wx.Frame.__int__(self,parent,id,title="滑稽", pos=(0,0),size=(1366,768))
  1. 字体设置错误, 没有 wx.default
        font=wx.Font(16,wx.default,wx.FONTSTYLE_NORMAL,wx.NORMAL)
  1. 没有设置结束动作
    def OnExit(self, event):
        """Close the frame, terminating the application."""
        self.Close(True)
  1. 其他不同的修改如下
import wx


class MyFarm(wx.Frame):

    def __init__(self,parent,id):

        super().__init__(parent,id,title="滑稽", pos=(0,0),size=(1366,768))
        panel=wx.Panel(self)
        title=wx.StaticText(panel,label='看来你还真点了',pos=(100,20))
        font=wx.Font(16,wx.FONTFAMILY_DEFAULT,wx.FONTSTYLE_NORMAL,wx.NORMAL)
        for i in range(50, 490, 20):
            wx.StaticText(panel,label="滑稽",pos=(50,i))

    def OnExit(self, event):
        """Close the frame, terminating the application."""
        self.Close(True)


if __name__=='__main__':

    if 'app' in globals():
        del app
    app = wx.App()
    frame = MyFarm(parent=None,id=1)
    frame.Show()
    app.MainLoop()
3年前 评论
acup (楼主) 3年前
acup (楼主) 3年前
acup (楼主) 3年前
Jason990420 (作者) 3年前
Coolest 3年前
Jason990420 (作者) 3年前
acup (楼主) 3年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!