By default Tkinter still uses the old Windows 2000-style widgets (random example):
but I want it to use the Windows XP/Vista/7-style widgets instead:
How can I do this? I would prefer to use the latest style version, so Windows 7 > Vista > XP > 2000.
On Windows, use tkinter.ttk to get the the themed version of Tk.
The ttk themed widgets are what you are looking for. Be sure to use the 'vista' theme to get native appearance on Vista/Win7.
Related
As far as I understand, it is not possible to modify the tkinter.colorchooser.askcolor as it uses the systems colorpicker dialog. Is this true?
from the source code: https://github.com/python/cpython/blob/3.9/Lib/tkinter/colorchooser.py
# this module provides an interface to the native color dialogue
# available in Tk 4.2 and newer.
The reason being is I wish to add an entry box to the dialog so that I would get the color code and user-entered text returned. Maybe it is possible to embed the dialog within a larger window? Is something like this possible, without using multiple windows?
I cannot find previous discussion anywhere else so I guess it is not a simple issue.
As far as I understand, it is not possible to modify the tkinter.colorchooser.askcolor as it uses the systems colorpicker dialog. Is this true?
Yes, that is true. At least on Windows and OSX. On Linux it's a custom dialog written in tcl/tk. You could start with that code and then make modifications to it, then write a tkinter wrapper around it. That wouldn't be particularly difficult if you know tcl/tk, but it's not exactly trivial either.
Maybe it is possible to embed the dialog within a larger window?
No, it's not.
I am trying to change the background color of the ttk Notebook widget in my python tkinter application so that it matches the blue color instead of being white.
I've tried searching for hours but to no avail. Is it not working because I'm working on a mac?
tabs_notebook = ttk.Notebook(self)
tabs_notebook.configure(bg=DARKBLUE)
tabs_notebook.pack()
view_tab = ttk.Frame(tabs_notebook)
new_tab = ttk.Frame(tabs_notebook)
tabs_notebook.add(view_tab, text="View Patient Details")
tabs_notebook.add(new_tab, text="Add New Patient")
One of the major complaints levelled at Tk was that it was ugly. This was mostly because it never fit the native look and feel of the hosting environment and because the amount of configuration options provided meant application developers tended to roll their own style which never fit well with any other applications. The other problem was that on Windows and MacOS Tk used naive rendering APIs to draw buttons and other UI elements but failed to keep up when these platforms introduced theming. As a result even if the Tk application looked ok on default Windows XP, it would look out of place where a user selected an alternate theme.
So in developing ttk (themed Tk) one of the primary design goals was to ensure that the default theme fit the current platform. On Windows and MacOS this means that UI elements are drawn using the native theming APIs. On Linux - it just has to make a best guess.
In your specific case the notebook elements are being drawn using MacOS themeing API calls and you cannot change the colors for this theme from Tk. However, what you can do is define an entire Tk theme. There are some examples in Tk code doing this and these were imported to Python by someone. Those should yield enough to generate a new theme using Tk drawing APIs and possibly images for some elements to allow for a fully custom theme should you require that amount of customization.
I'm wondering if there is any python code I can use to lock the size of my CMD window? I'm making a small text adventure game and want t at a specific size.
If it helps, I'm using windows 7, but wouldn't mind mac and linux compatible instructions. Thanks.
I don't think this is possible. If you want to control a gui directly, you should use a gui package like tkinter
for example
from Tkinter import *
window = Tk()
window.minsize(minw, minh)
window.maxsize(maxw, maxh)
add a text block to this and treat it just like a cmd window. You can read more about it on the Tkinter docs
you can use pyWinGUI for emulate text terminal with comctl.Edit control
Is there any way in python's Tkinter, bwidget or anything similar to show a Windwos' default progress bar?
I already know the bwidget.ProgressBar, but it produces an ugly progress bar while I mean showing a valid windows progress bar - the green, glowing one:
http://imageshack.us/photo/my-images/853/unledtph.png/
I need it because that way Windows will automatically show the progress of my program in the task bar. Plus, it looks better.
If you are using a modern (2.7+) version of Tkinter you can try the ttk.ProgressBar which is part of Tkinter.
You can install the pyttk module separately.
from Tkinter import *
import ttk
root = Tk()
progressbar = ttk.Progressbar(orient=HORIZONTAL, length=200, mode='determinate')
progressbar.pack(side="bottom")
progressbar.start()
root.mainloop()
As far as the taskbar functionality, that is not available in Tkinter yet (at least to the best of my knowledge). You'll need to make use of the Windows API for that. Although this question is for PyQt, the answers should prove helpful. Hope it gets you started.
The simplest solution would appear to be to use themed Tk with the tkinter.ttk module included in Python 2.7 and 3.1. The Progressbar widget is what you want.
Since you appear to be considering other frameworks you might look at Qt or wxWidgets which look native and have excellent Python bindings.
Python 2.7 (32-bit) Windows: We're experimenting with Python 2.7's support for themed Tkinter (ttk) for simple GUI's and have come away very impressed!! The one area where the new theme support seems to have come up short is how OS specific common dialogs are wrapped.
Corrected: In other words, the MessageBox and ColorChooser common dialogs have "ugly" looking Win 95 style blocky looking buttons vs. the themed (rounded/gradient) buttons that normally show up on these common dialogs under XP, Vista, and Windows 7. (I'm testing on all 3 platforms with identical, un-themed results).
Note: The filedialog common dialogs (askopenfilename, askopenfilenames, asksaveasfilename, askdirectory) are all properly themed.
import tkMessageBox as messagebox
messagebox.showinfo()
import tkColorChooser as colorchooser
color = colorchooser.askcolor( parent=root, title='Customize colors' )
Any ideas on what's required to get Tkinter's MessageBox and ColorChooser common dialogs to be OS theme compatible (at least under Windows XP or higher)?
Your observation is mainly correct. I do see what you are referring to in the messagebox and the colorchooser. However, my filedialogs all seem to have properly rounded buttons, etc.
My recommendation for you on making the messagebox is to create your own messagebox using the TopLevel widget, and then define what you need on it and the appropriate behavior for the different buttons (it's definitely a bit harder than just using a messagebox, but if you really need the new style buttons, it'll work).
I don't think you can hack together a solution for the colorchooser problem, however.
I though for a minute that perhaps Python 3.1 had fixed this problem, but sadly, I tried and that isn't the case. I suppose if you need the user to pick a color, the buttons will have to be ugly.
An option to get better looking dialog boxes is to compile your script to an executable using pyinstaller. I explain this more thouroughly here.
tl;dr, it appears that compiling with pyinstaller allows you to have dialog boxes with the style of the currently running OS, but not custom styles.