小编use*_*192的帖子

允许调整窗口pyGame的大小

我试图允许调整此应用程序的大小,我把RESIZABLE标志,但当我尝试调整大小时,它会搞砸!试试我的代码.

它是一个网格程序,当窗口调整大小时我希望网格也调整大小/缩小.

import pygame,math
from pygame.locals import *
# Define some colors
black    = (   0,   0,   0)
white    = ( 255, 255, 255)
green    = (   0, 255,   0)
red      = ( 255,   0,   0)

# This sets the width and height of each grid location
width=50
height=20
size=[500,500]
# This sets the margin between each cell
margin=1


# Initialize pygame
pygame.init()

# Set the height and width of the screen

screen=pygame.display.set_mode(size,RESIZABLE)

# Set title of screen
pygame.display.set_caption("My Game") …
Run Code Online (Sandbox Code Playgroud)

python pygame

15
推荐指数
2
解决办法
2万
查看次数

如何使用wxPython中的AddSubclassFactory?

我无法在网上找到有关如何使用此方法的任何示例.我认为这可能是我将使用的东西.有人能为我提供一个如何使用这种方法的例子吗?

http://wxpython.org/docs/api/wx.xrc.XmlResource-class.html

python wxwidgets wxpython wxruby

6
推荐指数
1
解决办法
172
查看次数

内存中的文件,Python

我有一个文本字符串,我想用它创建一个 .txt 文件。我不想允许用户访问它(出于安全原因),所以我想将 .txt 文件存储在内存中(如果可能的话)。

例如: 字符串是:

'''
Username: Bob
Password: Coolness

'''
Run Code Online (Sandbox Code Playgroud)

我想将此字符串作为 .txt 文件保存到内存中。然后将其发送到另一个程序。

anotherprogram.exe mytxt.txt
Run Code Online (Sandbox Code Playgroud)

我环顾四周,想知道使用StringIO是否可以做到这一点?它说“将字符串作为文件读取和写入”。我不确定,如果您知道如何执行此操作,请回复。

python file-io file

5
推荐指数
1
解决办法
3845
查看次数

使用 wx.DC 设置背景颜色的更好方法

现在,我正在像这样设置背景颜色,

dc.DrawRectangle(0,0,width,height)

你知道设置背景颜色的更好方法吗?

http://wxpython.org/docs/api/wx.DC-class.html

python wxwidgets wxpython

5
推荐指数
0
解决办法
2006
查看次数

如何为小部件添加轮廓边框?

如何在wxpython中为窗口小部件添加轮廓边框?(任何小部件,例如,a wx.Button)

python wxwidgets wxpython

5
推荐指数
1
解决办法
6548
查看次数

覆盖Python

我希望能够做到以下几点

class Parent:
    def __init__(self):
        pass
    def Create(self):
        return 'Password'

class Child(Parent):
    def __init__(self):
        self.Create()
    def Create(self):
        return 'The '+self.Create #I want to return 'The Password'
Run Code Online (Sandbox Code Playgroud)

我想从一个覆盖它的函数中的子类中获取父函数.我不知道该怎么做.

这有点难以解释,如果您在理解上有困难,请发表评论.

编辑:

感谢大家的答案,我几乎认为这是不可能的.

python

4
推荐指数
2
解决办法
6594
查看次数

为什么这个字符串不适用于ast.literal_eval

我收到格式错误的字符串错误.

这是我的测试

>>> eval("'Hello:: '+'fdsfds'")
'Hello:: fdsfds'
>>> import ast
>>> ast.literal_eval("'Hello:: '+'fdsfds'")
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    ast.literal_eval("'Hello:: '+'fdsfds'")
  File "C:\Python27\lib\ast.py", line 80, in literal_eval
    return _convert(node_or_string)
  File "C:\Python27\lib\ast.py", line 79, in _convert
    raise ValueError('malformed string')
ValueError: malformed string
Run Code Online (Sandbox Code Playgroud)

python string eval

4
推荐指数
1
解决办法
6840
查看次数

在python中获取所有属性XML并将其变为字典

XML:

<main>
    <item name="item1" image="a"></item>
    <item name="item2" image="b"></item>
    <item name="item3" image="c"></item>
    <item name="item4" image="d"></item>
</main>
Run Code Online (Sandbox Code Playgroud)

蟒蛇:

xmldoc = minidom.parse('blah.xml')
itemlist = xmldoc.getElementsByTagName('item')
for item in itemlist :
    #####I want to make a dictionary of each item
Run Code Online (Sandbox Code Playgroud)

所以我会得到

{'name':'item1','image':'a'}
{'name':'item2','image':'b'}
{'name':'item3','image':'c'}
{'name':'item4','image':'d'}
Run Code Online (Sandbox Code Playgroud)

有谁知道如何做到这一点?有功能吗?

python xml dom

3
推荐指数
2
解决办法
7017
查看次数

获取函数,Python的关键字参数

def thefunction(a=1,b=2,c=3):
    pass

print allkeywordsof(thefunction) #allkeywordsof doesnt exist
Run Code Online (Sandbox Code Playgroud)

会给[a,b,c]

是否有像allkeywordsof这样的功能?

我不能改变里面的任何东西, thefunction

python function introspection

3
推荐指数
2
解决办法
3621
查看次数

标签 统计

python ×9

wxpython ×3

wxwidgets ×3

dom ×1

eval ×1

file ×1

file-io ×1

function ×1

introspection ×1

pygame ×1

string ×1

wxruby ×1

xml ×1