我希望能够在一个帧中显示Notebook和TxtCtrlwx小部件.下面是一个改编自wxpython wiki的例子; 是否有可能改变他们的布局(可能有类似的东西wx.SplitterWindow)来显示Notebook同一帧下面的文本框?
import wx
import wx.lib.sheet as sheet
class MySheet(sheet.CSheet):
def __init__(self, parent):
sheet.CSheet.__init__(self, parent)
self.SetLabelBackgroundColour('#CCFF66')
self.SetNumberRows(50)
self.SetNumberCols(50)
class Notebook(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(600, 600))
menubar = wx.MenuBar()
file = wx.Menu()
file.Append(101, 'Quit', '' )
menubar.Append(file, "&File")
self.SetMenuBar(menubar)
wx.EVT_MENU(self, 101, self.OnQuit)
nb = wx.Notebook(self, -1, style=wx.NB_BOTTOM)
self.sheet1 = MySheet(nb)
self.sheet2 = MySheet(nb)
self.sheet3 = MySheet(nb)
nb.AddPage(self.sheet1, "Sheet1")
nb.AddPage(self.sheet2, "Sheet2")
nb.AddPage(self.sheet3, "Sheet3")
self.sheet1.SetFocus()
self.StatusBar()
def StatusBar(self): …Run Code Online (Sandbox Code Playgroud) 我有一个wx.Frame,其中我有一个包含两个项目的垂直BoxSizer,一个TextCtrl和一个自定义小部件.我希望自定义小部件具有固定的像素高度,而TextCtrl将正常扩展以填充窗口.我该怎么办?
如何在wxPython中仅更改对象的高度,使其宽度自动?在我的情况下,它是一个TextCtrl.
如何使窗口的高度可以更改并锁定宽度?
我一直在寻找互联网,但我不确定是否有办法在2个独立窗口中显示wxPython中的2个类.我们可以在它们之间进行通信(比如一个类是对话框而另一个类是主类)?
我想我在使用之前就这样做了,Show()但我不知道如何重复这个.
所以基本上我希望能够有一个对话但是通过使用类来代替.这比使用Modal对话框更强大.
谢谢
我用我的WxPython脚本创建了一个.app,它刚刚完成.问题是,菜单栏标题显示为"Python".怎么能改变?我会使用wx.Menu()/ wx.MenuBar(),还是.app文件本身的问题?
以下是我在SO上找到的示例托盘图标应用程序的略微修改的源代码:
import wx
TRAY_TOOLTIP = 'System Tray Demo'
TRAY_ICON = 'icon.png'
def create_menu_item(menu, label, func):
item = wx.MenuItem(menu, -1, label)
menu.Bind(wx.EVT_MENU, func, id=item.GetId())
menu.AppendItem(item)
return item
class TaskBarIcon(wx.TaskBarIcon):
def __init__(self):
super(TaskBarIcon, self).__init__()
self.set_icon(TRAY_ICON)
self.Bind(wx.EVT_TASKBAR_LEFT_DOWN, self.on_left_down)
def CreatePopupMenu(self):
menu = wx.Menu()
create_menu_item(menu, 'Say Hello', self.on_hello)
menu.AppendSeparator()
create_menu_item(menu, 'Exit', self.on_exit)
return menu
def set_icon(self, path):
icon = wx.IconFromBitmap(wx.Bitmap(path))
self.SetIcon(icon, TRAY_TOOLTIP)
def on_left_down(self, event):
print 'Tray icon was left-clicked.'
def on_hello(self, event):
print 'Hello, world!'
def on_exit(self, event):
wx.CallAfter(self.Destroy)
class App(wx.App):
def OnInit(self): …Run Code Online (Sandbox Code Playgroud) 我正在开展一个学校项目,在python平台上开发一个定制的媒体播放器.问题是当我使用time.sleep(duration)时,它会阻止我的GUI的主循环,阻止它更新.我咨询了我的主管,并被告知要使用多线程,但我不知道如何使用线程.有人会建议我如何在下面的场景中实现线程吗?
def load_playlist(self, event):
playlist = ["D:\Videos\test1.mp4", "D:\Videos\test2.avi"]
for path in playlist:
#calculate each media file duration
ffmpeg_command = ['C:\\MPlayer-rtm-svn-31170\\ffmpeg.exe', '-i' , path]
pipe = subprocess.Popen(ffmpeg_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
results = pipe.communicate()
#Regular expression to get the duration
length_regexp = 'Duration: (\d{2}):(\d{2}):(\d{2})\.\d+,'
re_length = re.compile(length_regexp)
# find the matches using the regexp that to compare with the buffer/string
matches = re_length.search(str(results))
#print matches
hour = matches.group(1)
minute = matches.group(2)
second = matches.group(3)
#Converting to second
hour_to_second = int(hour) * …Run Code Online (Sandbox Code Playgroud) 我正在尝试在wxPython中安排一些面板.布局的粗略表示如下:
基本上,我正在寻找一个左右面板,这样 - 当调整大小时 - 左(橙色)面板(及其内容)永远不会调整大小,右(蓝色)面板可以根据需要拉伸/增长,但只是水平的.
我到目前为止的代码(带有一些随机填充小部件)如下所示.我的问题遵循以下代码:
import wx
import wx.lib.scrolledpanel as scrolled
class MainWindow(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent)
#add position panel
posPnl = IdPanel(self)
lbl1 = wx.StaticText(posPnl, label="Position")
lbl2 = wx.StaticText(posPnl, label="Size")
sizeCtrl = wx.TextCtrl(posPnl)
posPnlSzr = wx.BoxSizer(wx.VERTICAL)
posPnlSzr.Add(lbl1, 1, wx.FIXED&wx.LEFT)
posPnlSzr.Add(sizeCtrl, 1, wx.LEFT&wx.FIXED)
posPnlSzr.Add(lbl2, 1, wx.FIXED&wx.LEFT)
posPnl.SetSizer(posPnlSzr)
posPnl2 = TimelinePanel(self)
lbl12 = wx.StaticText(posPnl2, label="Position")
lbl22 = wx.StaticText(posPnl2, label="Size")
sizeCtrl2 = wx.TextCtrl(posPnl2)
posPnlSzr2 = wx.BoxSizer(wx.VERTICAL)
posPnlSzr2.Add(lbl12, 1, wx.GROW)
posPnlSzr2.Add(sizeCtrl2, 1, wx.GROW)
posPnlSzr2.Add(lbl22, 1, wx.GROW)
posPnl2.SetSizer(posPnlSzr2)
mainSzr = …Run Code Online (Sandbox Code Playgroud) 如何生成python代码?我知道我需要将code_generation属性从C++更改为Python,但是没有Python选项......我该如何解决这个问题?我已经尝试在互联网上寻找这个问题,但我找不到任何东西.
我目前正在开发一个python项目,它是一个不与internet交互的应用程序.GUI正在与wxpython一起用餐.python中是否有代码可以模拟按钮点击.
wxpython ×10
python ×8
layout ×2
.app ×1
blocking ×1
boxsizer ×1
buttonclick ×1
macos ×1
media ×1
media-player ×1
python-2.7 ×1
resize ×1
simulate ×1
size ×1
system-tray ×1
widget ×1
wxwidgets ×1