pygame 中是否有类似的功能?
screen.fill(pygame.image.load('brick.bmp').convert())
Run Code Online (Sandbox Code Playgroud)
我想用图像填充窗口(背景)以产生与此类似的效果:

我唯一的想法是将每块砖块放到屏幕上,但我认为这会减慢游戏速度。有没有人知道如何做到这一点(并提供一些示例代码)?
这是一个有效但运行缓慢的方法的片段
While True:
for y in range(0,600,32):
for x in range(0,800,32):
screen.blit( self.img,(x,y))
...
pygame.display.flip()
Run Code Online (Sandbox Code Playgroud) i="<wx._controls.Button; proxy of <Swig Object of type 'wxButton *' at 0x2887828> >]], [[[41, 183], 'Button', <wx._controls.Button; proxy of <Swig Object of type 'wxButton *' at 0x28879d0> >]]]"
m = re.findall("<wx.(.*)> >", i)
Run Code Online (Sandbox Code Playgroud)
会给我的
["<wx._controls.Button; proxy of <Swig Object of type 'wxButton *' at 0x2887828> >]], [[[41, 183], 'Button', <wx._controls.Button; proxy of <Swig Object of type 'wxButton *' at 0x28879d0> >"]
Run Code Online (Sandbox Code Playgroud)
不过我想要它给我,
["<wx._controls.Button; proxy of <Swig Object of type 'wxButton *' at 0x2887828> >","<wx._controls.Button; proxy of <Swig Object of type 'wxButton …Run Code Online (Sandbox Code Playgroud) 我尝试过(但什么也没发生)
self.txt.SetBackgroundColour ((255,0,0))
Run Code Online (Sandbox Code Playgroud)
正如标题中所述,我正在尝试更改 StyledTextCtrl 的背景颜色。有谁知道可以使用的方法吗?我检查了 API 文档,但似乎找不到,http://wxpython.org/docs/api/wx.stc.StyledTextCtrl-class.html
(当然,我所说的背景颜色是指整个书写区域)
有谁知道我可以做到这一点的方法吗?
编辑:
下面的代码中背景没有改变
import wx
import wx.stc
app = wx.App(redirect=True)
top = wx.Frame(None, title="StyledTXTCtrl", size=(300,200))
txt=wx.stc.StyledTextCtrl(top)
txt.SetBackgroundColour((255,255,0))
txt.Refresh()
top.Show()
app.MainLoop()
Run Code Online (Sandbox Code Playgroud) 让我说我有这个示例代码:
import wx
app = wx.App(False) # Create a new app, don't redirect stdout/stderr to a window.
frame = wx.Frame(None, wx.ID_ANY, "Hello World") # A Frame is a top-level window.
s=wx.Button(frame,-1,"New")
frame.Show(True) # Show the frame.
app.MainLoop()
Run Code Online (Sandbox Code Playgroud)
就像在某些程序中一样,如果按下"新建"按钮,它将在另一个窗口中再次打开程序.我想知道,我怎么能在python中做到这一点?
我不能创建一个窗口对象,然后复制它,因为在我的实际程序中我使用全局变量,这些全局变量只用于一个窗口.
似乎我唯一的选择是找到再次运行程序的方法.
我有这个代码:
import re
#TEST CASES
match_dict = ['hello(here)',
'Hello (Hi)',
"'dfsfds Hello (Hi) fdfd' Hello (Yes)",
"Hello ('hi)xx')",
"Hello ('Hi')"]
for s in match_dict:
print "INPUT: %s" % s
m = re.sub(r"(?<!\()'[^']+'", '', s, flags=re.M)
paren_quotes = re.findall(r"Hello\s*\('([^']+)'\)", m, flags=re.M)
output = paren_quotes if paren_quotes else []
m = re.sub(r"Hello\s*\('[^']+'\)", '', m, flags=re.M)
paren_matches = re.findall(r"Hello\s*\(([^)]+)\)", m, flags=re.M)
if paren_matches:
output.extend(paren_matches)
print 'OUTPUT: %s\n' % output
Run Code Online (Sandbox Code Playgroud)
这段代码用于输出'Hello'后面括号中的所有内容,
Hello (Hi) would give 'Hi'
Run Code Online (Sandbox Code Playgroud)
我的问题是当我投入时:
Hello('Hi')
Run Code Online (Sandbox Code Playgroud)
...... 'Hi' 当我希望它返回时它仍然会返回"'Hi'"
有谁知道我怎么能修复这段代码?
为什么这个正则表达式不起作用?
import re
i="<wx._controls.Button; proxy of <Swig Object of type 'wxButton *' at 0x2d040b0> >"
m = re.match("controls(.*)[;]", i)
if m:
print m.group(1)
Run Code Online (Sandbox Code Playgroud)
它什么都不返回.我试图让一切介于两者之间,"控制"和";" 此解决方案适用于其他测试用例,但不适用于此测试用例.
我试图用逗号分隔字符串","
例如:
"hi, welcome" I would like to produce ["hi","welcome"]
Run Code Online (Sandbox Code Playgroud)
然而:
"'hi,hi',hi" I would like to produce ["'hi,hi'","hi"]
"'hi, hello,yes','hello, yes','eat,hello'" I would like to produce ["'hi, hello,yes'","'hello, yes'","'eat,hello'"]
"'hiello, 332',9" I would like to produce ["'hiello, 332'","9"]
Run Code Online (Sandbox Code Playgroud)
我不认为这个.split()功能可以使用,有没有人知道我可以这样做的方式,也许是正则表达式?
这是一个片段
kit.insertHTML(doc, doc.getLength(), "Hello", 0, 0, null);
try{
Thread.sleep(1000);
}catch(Exception e){}
Run Code Online (Sandbox Code Playgroud)
我正在使用HTMLEditorKit()并HTMLDocument()作为文本框.文本框应该显示"Hello"然后等待一秒然而,当我尝试这个时,它等待一秒然后把单词"Hello"这不是我想要的.
我不确定为什么会这样,因为我把它按逻辑顺序排列.如果有人能帮助我,那就太好了.
编辑:
有没有人知道另一种选择,所以我可以使用"延迟"的那种效果?
让我们说我有一个字符串
s="""
print 'hi'
print 'hi'
print 3333/0
"""
Run Code Online (Sandbox Code Playgroud)
是否有可以帮助我检查此字符串语法的模块或方法?
我希望输出如下:
第2行,缩进第3行,除以零
我听说过pyFlakes,pyChecker和pyLint,但那些检查文件,而不是字符串.
可以说我有这个字符串:
myString="'Hello'+yes+'Whats hello'6"
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种方法来删除引号中的所有内容
所以,它会成为:
"+yes+"
Run Code Online (Sandbox Code Playgroud)
因为'Hello'和'Whats hello'用引号括起来.而6是一个数字.
有没有办法做到这一点?也许使用正则表达式?我尝试用For循环做这个,但我猜我的逻辑不是很好.