Python | Tkinter | TkCalendar : how to customize 'DateEntry Date Picker' object? like increasing Width, and more? - python-2.7

I'm developing a simple Python stand-alone application, that uses a GUI datePicker, and I went for using 'from tkcalendar import DateEntry'. | using python 2.7 (for older windows PC)
while using 'DateEntry - Date Picker', I not able to find a few major things, even the documentation doesn't explain on this. I went through these:
https://tkcalendar.readthedocs.io/en/stable/DateEntry.html#
https://tkdocs.com/shipman/
https://www.plus2net.com/python/tkinter-DateEntry.php
I'm looking ways to
Change width of Widget
open widget on click of entry/input bar (not only drop-down arrow)
Code Ex:
DateEntry(window, date_pattern='yyyy-MM-dd', width= 67, background=CONST.TITLE_BG_COLOR, bad=2)
Any suggestion, references and even alternative are appreciated. Thanks.

Related

wxWidgets/C++/Code::Blocks: Failed to import font from system library

I've been making a simple app in C++/wxWidgets that just has a catalog of Garfield comix from the Internet, without the annoying ads and offers. (Don't ask me how I got access to the PNG files of each comic in the first place, because my name already explains that)
Anyway, I'm trying to make a static text with a specific font (in my case, that would be Tahoma size 8. I'm going to make it bold but for sake of simplicity I haven't done it yet). I use the following line of code to import it from the Windows internal font catalog:
wxFont *CC_FONT_Tahoma_Bold(8, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxT("Tahoma"), wxFONTENCODING_DEFAULT);
but whenever I try that it just fails and gives the following error message (I'm using mingw-w64 8.1.0 if that helps):
error: cannot convert 'wxFontEncoding' to 'wxFont*' in initialization
I have no idea what this means and I have tried to change the font encoding to every possible value, but still no progress. Also, I am creating the font in the App's OnInit function. I have also tried to put it in a different function. Please help.
Turns out, I just made a silly mistake. 🤣🤪
The real code I should have used is:
wxFont *CC_FONT_Tahoma_Bold = new wxFont(8, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxT("Tahoma"), wxFONTENCODING_DEFAULT);

Better looking Tkinter File Dialogs for Python 2.7

In my application, the user needs to browse for files. However, the askdirectory from tkFileDialog isn't really comfortable for using and browsing files since it's somewhat outdated.
It looks like this:
What I want to achieve should look like the "default" windows browse dialog. Like this:
(Source https://www.pythontutorial.net/tkinter/tkinter-open-file-dialog/)
I am not sure (since I couldn't find proof) but I remember someone telling me that it looks like this because I am using Python 2.7 and not 3+.
Is that true? Does an alternative exist?
It seems it has something to do with your version, as I have done a bit of research and I am using python 3 with the included tkinter and it shows a normal windows explorer popup. So, if you are using one of the up-to-date versions, it should be the OS' default. (I am unable to test that as python 2 will not work properly on my machine although I can confirm since you are using an older one)
I recreated your case with this code:
from tkinter import *
root = Tk()
filedialog.askdirectory()
root.mainloop()
You can try using askopenfilename(). It displays the standard Open File dialog box.
For example:
from tkinter import *
from tkinter import filedialog as fd
root = Tk()
root.title("Button to open files")
root.geometry("500x500")
def openfd(*args):
askk = askopenfilename()
btn = Button(root, text="Click to open file", command=openfd)
btn.place(x=200, y=200)
root.mainloop()
You can read more about it at https://www.pythontutorial.net/tkinter/tkinter-open-file-dialog/.

Cannot insert a image in Tkinter Label even after anchoring it

Code Here is my code
I've attached a link of well formatted code image and file
import os.
from Tkinter import *.
root=Tk().
m=Label(root,text="Processing...",fg="bue",font="calibri 35 bold").
os.chdir("f:\\").
im=PhotoImage("MM.jpg")
ok=Toplevel(root)
s=Label(root,text="Img",image=im)
s.photo=im
s.image=im
s.grid(row=0,column=0) m.grid(row=1,column=0)
but=None.
def dat():.    
global s,root,but.    
s.destroy().    
m.destroy().
but=Label(root,text="Done").  
but.pack().
  root.overrideredirect(False).
root.mainloop().
I've attached a image of properly indented code in the link
or my file's drive link
Drive link
Please reformat your code so that you can get better help and quickly.
Meanwhile I have a code below showing you how to properly open a .jpg file and have it appear in a tk.Label. I hope this basics can guide you to solve your code problem.
from Tkinter import *
from PIL import Image, ImageTk #added
root=Tk()
filename = "minion.jpg" # Put your filename (can also use full path)here
im = Image.open(filename) #added
im=ImageTk.PhotoImage(im) #revised
s=Label(root,text="Img",image=im)
s.grid(row=0,column=0)
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
root.mainloop()
Update:
I have added the image commands into your script. Do note, your code contained several wrong indents, which pycharm highlighted to me. There were typos, wrong placement of certain commands and missing import statement. I took the liberty to correct them sufficient enough for tkinter to generate a tk window with your label and image, so to be able to answer your question. A screen shot of pycharm with python2.7, a revised code and tk window with label and image is attached below.
Note: For .jpg image you need the PIL or Pillow modules installed to open such file type. Do make sure you have that. If you don't have, follow the instructions in this webpage to install it. That is the limitation of the PIL.ImageTk.PhotoImage method. You can read more from this website.

Read window's registry in QT

I want to list all application which had been installed by reading uninstall registry file from HKEY_CURRENT_USER. But look like it can't be done by using QSettings, for some security reason ( i guess ).
QSettings maya("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall
People suggest to use WinAPI to accomplish this (at least, on Window platform)
Can somebody guide me how to add and use this lib please?
Thank
In order to get the list of all sub items under the "Uninstall" one in the Windows registry you need to use QSettings::childGroups() function, i.e:
QSettings m("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall",
QSettings::NativeFormat);
QStringList ak = m.childGroups();
This will return the list of all installed applications.
UPDATE:
After getting the list of installed applications one can read the installation details. There are two ways for doing that. For example to read the "UinstallPath" key for "Autodesk Maya 2014" application:
m.beginGroup("Autodesk Maya 2014");
QString path = m.value("UninstallPath").toString();
m.endGroup();
or simply:
QString path = m.value("Autodesk Maya 2014/UninstallPath").toString();

Disable or Catch VTK warnings in vtkOutputWindow when embedding Mayavi

I'd like to either disable the VTK warning window or, better yet, catch them to handle with my application's logging system. My application is using an embedded mayavi view, and I don't want error windows popping up that I have no control over. The following code demonstrates the warning window.
import numpy as np
from mayavi import mlab
x1 = np.array([1, 1, 2, 3])
y1 = np.array([1, 1, 4, 2])
z1 = np.array([1, 1, 5, 1])
mlab.plot3d(x1, y1, z1)
mlab.show()
Ok, I've done some research and discovered that vtk.vtkObject.GlobalWarningDisplayOff() will disable the window completely, which is nice. Better yet the followingcode will log the warnings to a file (found it here):
def redirect_vtk_messages ():
""" Can be used to redirect VTK related error messages to a
file."""
import tempfile
tempfile.template = 'vtk-err'
f = tempfile.mktemp('.log')
log = vtkpython.vtkFileOutputWindow()
log.SetFlush(1)
log.SetFileName(f)
log.SetInstance(log)
So while this is nice, I'm still unable to pipe the warnings directly into a logging handler. I'd rather not have to have a vtk_log file next to my regular log files. Also I might want to handle the warnings in my GUI somehow, or give the user options on how to handle them and constantly watching a log file for changes seems like a poor way to do that.
Any suggestions on a robust pythonic way to handle vtk warnings in an application which embeds mayavi/vtk?
I don't know whether this will work in the Mayavi environment, but this works for Python wrappings to VTK
# pipe vtk output errors to file
errOut = vtk.vtkFileOutputWindow()
errOut.SetFileName("VTK Error Out.txt")
vtkStdErrOut = vtk.vtkOutputWindow()
vtkStdErrOut.SetInstance(errOut)
I guess this partially answer your question, but you could implement an error observer in python as explained here http://public.kitware.com/pipermail/vtkusers/2012-June/074703.html and add it to the vtk class you are interested.
In c++ I find much simpler to redirect the output to stderr (this example is for windows):
vtkSmartPointer<vtkWin32OutputWindow> myOutputWindow = vtkSmartPointer<vtkWin32OutputWindow>::New();
myOutputWindow->SetSendToStdErr(true);
vtkOutputWindow::SetInstance(myOutputWindow);
In python I tried
ow = vtk.vtkOutputWindow()
ow.SendToStdErrOn()
it sends the error to console, but I still see the vtk window and it doesn't really seem catching the errors.
Another option could be to recompile vtk with VTK_USE_DISPLAY turned off ( http://osdir.com/ml/python-enthought-devel/2009-11/msg00164.html). I am not going to try this because I am using the vtk distribution already compiled in paraview
You can create a subclass deriving from vtkOutputWindow and implement your message handling in the method void DisplayText(const char* someText). I did this is in a C++ project to redirect all output to cerr and even suppress specific warnings.
An approach I found similar to #SciCompLover's answer that suppresses the output window while also printing to the console:
import vtk
vtk_out = vtk.vtkOutputWindow()
vtk_out.SetInstance(vtk_out)
Tested on Mayavi 4.7.1 with VTK 8.2.0 on Windows and MacOS.