我试图允许调整此应用程序的大小,我把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) 我无法在网上找到有关如何使用此方法的任何示例.我认为这可能是我将使用的东西.有人能为我提供一个如何使用这种方法的例子吗?
我有一个文本字符串,我想用它创建一个 .txt 文件。我不想允许用户访问它(出于安全原因),所以我想将 .txt 文件存储在内存中(如果可能的话)。
例如: 字符串是:
'''
Username: Bob
Password: Coolness
'''
Run Code Online (Sandbox Code Playgroud)
我想将此字符串作为 .txt 文件保存到内存中。然后将其发送到另一个程序。
anotherprogram.exe mytxt.txt
Run Code Online (Sandbox Code Playgroud)
我环顾四周,想知道使用StringIO是否可以做到这一点?它说“将字符串作为文件读取和写入”。我不确定,如果您知道如何执行此操作,请回复。
现在,我正在像这样设置背景颜色,
dc.DrawRectangle(0,0,width,height)
你知道设置背景颜色的更好方法吗?
如何在wxpython中为窗口小部件添加轮廓边框?(任何小部件,例如,a wx.Button)
我希望能够做到以下几点
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)
我想从一个覆盖它的函数中的子类中获取父函数.我不知道该怎么做.
这有点难以解释,如果您在理解上有困难,请发表评论.
编辑:
感谢大家的答案,我几乎认为这是不可能的.
我收到格式错误的字符串错误.
这是我的测试
>>> 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) 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)
有谁知道如何做到这一点?有功能吗?
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