I need to ask the user (me) to for a *new* folder, but all I can find is "askdirectory".
1) there does not seem to be a "create new folder" option
2) Providing it with an existing path with a suggested foldername just lets it default to the current folder (instead of the existing parent)
3) When providing a non-existing path clicking the OK button twice returns it anyway - without any signs of doing so. Not quite intuitive (and yes, I'm aware I can provide a "must exist" setting, but that would block /any/ attempt of creating a new folder).
I've been googeling for a solution but did not find much of anything, let alone a straight answer to this not really unique situation. Lots of clumsy "work-arounds" though :-(
tl;dr: How do I get tkinter to display a "new folder" dialog ?
Regards, Rudy Wieser
Didn't find your answer? Ask the community — no account required.
D
Dennis Lee Bieber
On Tue, 5 May 2020 10:49:19 +0200, "R.Wieser" declaimed the following:
The short answer is that you probably have to subclass/extend the current dialog to add some button for "new directory" -- on clicking that button you present a dialog for a directory name (relative to current selected path), and use os.mkdir() to create the directory. Then refresh the dialog to add the new directory to its display...
I've only touched on tkinter some 20 years ago, and hated it -- trying to figure out what attributes were Python level vs stuff in the underlying TCL/TK library was painful.
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/
R
R.Wieser
Dennis,
Hello again. :-)
That ... was something I wanted to evade. Subclassing a tkinter GUI element is a whole new area for me, and I'm not even sure I want to go there (got enough other stuff to do).
I won't claim I hate it, but its currently a bit awkward to me too (it might still "grow" on me though). Starting with not even being able to put a dialog up (like the above one) without a "root" window being created too - which than has to be suppressed and ... Well, I'm sure that I will encounter some "interresting" effects because of that suppression later on.
But, if I want to have some GUI-based user interaction I don't think I've got much choice than to use tkinter.
Regards, Rudy Wieser
D
Dennis Lee Bieber
On Tue, 5 May 2020 20:53:12 +0200, "R.Wieser" declaimed the following:
formatting link
formatting link
(though "Phoenix" may not be available on ARM systems)
OTOH...
-=-=-=- pi@rpi3bplus-1:~$ apt search wxpython Sorting... Done Full Text Search... Done cain/stable 1.10+dfsg-3 all simulations of chemical reactions
python-wxgtk4.0/stable 4.0.4+dfsg-2 armhf Python interface to the wxWidgets Cross-platform C++ GUI toolkit
python3-wxgtk4.0/stable,now 4.0.4+dfsg-2 armhf [installed] Python 3 interface to the wxWidgets Cross-platform C++ GUI toolkit
pi@rpi3bplus-1:~$ sudo apt install python-wxgtk4.0 Preparing to unpack .../python-wxgtk4.0_4.0.4+dfsg-2_armhf.deb ... Unpacking python-wxgtk4.0 (4.0.4+dfsg-2) ... Setting up python-sip (4.19.14+dfsg-2) ... Setting up python-wxgtk4.0 (4.0.4+dfsg-2) ...
pi@rpi3bplus-1:~$ sudo apt install python3-wxgtk4.0 wx3.0-doc Reading package lists... Done Building dependency tree Reading state information... Done python3-wxgtk4.0 is already the newest version (4.0.4+dfsg-2).
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/
D
Dennis Lee Bieber
On Tue, 05 May 2020 15:46:44 -0400, Dennis Lee Bieber declaimed the following:
ADDENDUM:
pi@rpi3bplus-1:~$ python3 Python 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0] on linux Type "help", "copyright", "credits" or "license" for more information.
'4.0.4'
'4.0.4 gtk3 (phoenix) wxWidgets 3.0.4'
... So appears to be there for recent Raspbian/Buster.
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/
D
Dennis Lee Bieber
On Tue, 05 May 2020 15:46:44 -0400, Dennis Lee Bieber declaimed the following:
SECOND ADDENDUM:
There are also binding for pyqt5 shown in the package list on Raspbian, but I have even less knowledge of the QT5 library (bad enough my wxPython books cover 2.x-3.x, I just ordered a book covering wxPython 4.x [Phoenix] as there are some significant changes
formatting link
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/
R
R.Wieser
Dennis,
Thanks. Although I'm a bit of a sucker for whats installed by default, do you have any opinion about the easyness-of-use of WxWidgets (thats the name for them, isn't it?) compared to tkinter ?
Than again, I could not help myself to google for how to subclass tkinter elements. :-) Might be much easier than I thought. Will need to google some more.
(saw & read your other two post in this regard too)
Regards, Rudy Wieser
B
Bob Martin
For simple GUI interactions check out Zenity.
D
Dennis Lee Bieber
On Wed, 6 May 2020 08:59:28 +0200, "R.Wieser" declaimed the following:
The book covering Phoenix version
formatting link
isn't due to arrive until later in the month (~May 17).
formatting link
would be comparing the pre-Phoenix wxPython.
Just for giggles wxPython vs PyQT
formatting link
Interesting...
formatting link
is by the author of the book I listed above...
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com http://wlfraed.microdiversity.freeddns.org/
K
Kees Nuyt
For simple TUI interactions check out whiptail (AFAIK pre-installed on Raspbian).
Regards,
Kees Nuyt
B
Bob Martin
Thanks, I'll look at that, but Zenity does file and calendar selectors.
D
Dennis Lee Bieber
Resurrecting a near 2-week old thread...
On Wed, 6 May 2020 08:59:28 +0200, "R.Wieser" declaimed the following:
The book I'd ordered isn't as detailed as I'd like (it sure isn't an equivalent of the pre-Phoenix "wxPython In Action" book). It refers one to the on-line documentation for wxPython and basically just runs a sequence of examples from the equivalent of "Hello World", an image view, database viewer, ... FTP client.
However... Between the new book and
formatting link
I've hacked this somewhat wordy example... (no doubt everything could have been done directly in-line rather than the subclassed Panel and Frame -- but this the recommended style in the book). Watch out for line wrapping...
-=-=- import wx
class APanel(wx.Panel): def __init__(self, parent): super().__init__(parent) button = wx.Button(self, label="Select Directory") button.Bind(wx.EVT_BUTTON, self.on_button_press) self.directory = wx.TextCtrl(self, style=wx.TE_READONLY, size=(400, -1)) sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(button, proportion=0, flag=wx.ALL | wx.CENTER, border=5) sizer.Add(self.directory, proportion=0, flag=wx.ALL | wx.CENTER, border=5) self.SetSizer(sizer) def on_button_press(self, event): with wx.DirDialog(None, message="Choose a Directory", defaultPath="", size=(400, 400), style=wx.DD_DEFAULT_STYLE, # | wx.DD_DIR_MUST_EXIST, ) as dialog: # OR the DD_DIR_MUST_EXIST if suppressing New Directory button if dialog.ShowModal() == wx.ID_OK: self.directory.SetValue(dialog.GetPath()) #else user CANCELLED, don't set directory
... which runs on my Win10, Debian Buster in Oracle VirtualBox, and on an R-Pi 3B. Looking at the command history on the R-Pi, I'd had to execute
sudo apt install python3-wxgtk4.0 wx3.0-doc
to install wxPython Phoenix for Python3.x (I've run similar on the Debian, and probably used pip3 on Win10.
On Linux, it seems to open in "/home" (and does not display a "create directory" button at that level -- but as soon as you've clicked on a directory (eg: "pi") the create directory button appears in the window.
I'll admit I'm getting a few warnings when run on the R-Pi, which did not appear in full Debian Buster.