日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

wxpython 按钮跳notebook_按钮按下wxpython刷新窗口

發布時間:2023/12/19 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 wxpython 按钮跳notebook_按钮按下wxpython刷新窗口 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我一直在用我的Python程序遇到一些麻煩。基本上,它是一個非常非常簡單的文件管理器。

我一直試圖讓它在文件夾之間移動(用戶單擊一個文件夾,程序刷新顯示并顯示文件夾的內容)。

我遇到的問題是,我似乎無法讓按鈕刷新顯示,然后在單擊時用新文件夾和文件填充它。

這是我使用的代碼,它在Linux上。

import wx

import fileBrowser

class interface(wx.Frame):

def __init__(self, parent, id):

'''(object, int) --> None

Set up wx python in a frame and displays it and contents defined in this function on the screen.'''

wx.Frame.__init__(self, parent, id, "Bronto", size = (800, 600))

panel = wx.Panel(self)

self.createPanels()

contents = fileBrowser.print_items("/")

wx.StaticText(panel, -1, "/", (50, 10))

col = 50

row = 50

for items in contents:

name = items

col, row = self.makeIcons(panel, (800, 600), name, col, row)

def makeIcons(self, panel, param, name, col, row):

'''(object, object) --> None

Place a button on the window that uses an image as its icon.'''

pic = wx.Image("folder.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap()

self.button = wx.BitmapButton(panel, -1, pic, pos = (col, row))

wx.StaticText(panel, -1, name, (col + 10, row + 40))

self.Bind(wx.EVT_BUTTON, self.displayContents, self.button)

self.button.SetDefault()

if(col < 600):

return col + 90, row

else:

col = 50

return col, row + 80

def createPanels(self):

'''(object) --> None

Create and place both menu and status bars on the window.'''

status = self.CreateStatusBar()

menubar = wx.MenuBar()

File = wx.Menu()

Edit = wx.Menu()

menubar.Append(File,"File")

menubar.Append(Edit, "Edit")

new = wx.MenuItem(File, 101, '&New\tCtrl+N', 'Creates a new document')

File.AppendItem(new)

self.Bind(wx.EVT_MENU, self.NewApplication, id=101)

self.SetMenuBar(menubar)

def NewApplication(self, event):

app = wx.PySimpleApp()

frame = interface(parent = None, id =1)

frame.Show()

app.MainLoop()

def displayContents(self, event):

'''(event) --> None

Display the contents of the folder clicked on'''

#self.panel.Destroy();

#self.panel = wx.Panel(self)

self.Refresh(True)

contents = fileBrowser.print_items("/home")

col = 50

row = 50

for items in contents:

name = items

wx.Yield()

col, row = self.makeIcons(panel, (800, 600), name, col, row)

if __name__ == "__main__":

app = wx.PySimpleApp()

frame = interface(parent = None, id =1)

frame.Show()

app.MainLoop()這里是fileBrower程序(目前我只查看文件夾,但稍后會更改)

import os

import os.path

def print_items(d):

'''(str) -> NoneType

Print the list of files and directories in directory d, recursively,

prefixing each with indentation.'''

icons = []

#print out the names of files and subdirectories

for filename in os.listdir(d):

subitem = os.path.join(d, filename)

if os.path.isdir(subitem):

print filename

icons.append(filename)

return icons@pthonm:我添加了你建議的代碼,但它似乎沒有用新的東西更新它(它確實清除了窗口)

編輯:好吧,我幾乎有它的工作。我可以通過使用self.Refresh(True)來顯示內容,但只有在不使用self.panel.Destroy()方法時才能使用。所以,關于如何擺脫按鈕和文本的任何建議(請參閱我添加的displayContents方法)?

編輯2:我得到它的工作。我所做的是,我將其添加到我的displayContents方法。這可能不是這樣做的最好方法。

def displayContents(self, event):

'''(event) --> None

Display the contents of the folder clicked on'''

self.panel.Destroy();

self.panel = wx.Panel(self)

self.createPanels()

self.Update()

wx.StaticText(self.panel, -1, location, (50, 10))

contents = fileBrowser.print_items("/home/gum/Documents")

col = 50

row = 50

for directory,name in contents.iteritems():

col, row = self.makeIcons(self.panel, (800, 600), name, col, row)

總結

以上是生活随笔為你收集整理的wxpython 按钮跳notebook_按钮按下wxpython刷新窗口的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。