Vscode atom dark theme not highlighting tkinter - python

When I use from tkinter import * in vscode with atom one dark theme, I get no highlights from tkinter functions, though my code is still working.
In the picture, pack(), Tk(), Label and mainloop() is supposed to be highlighted (I know this, cause they are in the actual atom software).
Is there anyway to fix this?
Thanks!

There is nothing wrong with the code editor nor the theme. Its just how most of the theme works. Which part do you expect to be highlighted? All tkinter widgets(Label,Entry,etc.) are classes, and most themes do not have any highlighting for classes. I don't think much themes would have highlighting on class names and function names as its used very frequently.
"In the picture, pack(), Tk(), Label and mainloop() is supposed to be highlighted. Is there anyway to fix this?"
"Is supposed to be highlighted" is wrong words to use, as most themes does not highlight classes.
What usually has highlighting is, all the keywords and keyword arguments and string, etc. Since these are highlighted in your code, its working perfectly. I don't think there are any "special effects" for tkinter, as any theme for python is same as any theme for tkinter.
One way to get your desired effect, is to use a different theme, that actually will highlight classes (maybe monokai or some material themes?). I personally don't prefer alot of theme around, so something like this is perfect. Or the other way is to make or customize your themes, which can mess up the color if you are not sure what your doing.

I'm going to guess this is a problem on tkinters part and not the color theme but if it works on other themes and not one dark pro you can always try to change the exisiting colors using "yo generator code"
css-tricks does a good job showing how to install it: https://css-tricks.com/creating-a-vs-code-theme/
Altough they go through how to create your own theme. But you can always choose to import an existing theme.

Related

Python syntax highlighting using PyChar and IDLE

I have a text editor I'm working on. Using PyCharm. I have line number support (many thanks to Bryan Oakley!) and python syntax highlighting using IDLE Perculator. It works but some of the highlight code is hard to read. Oh yes, using tkinter for GUI support.
Can anyone point me at how to set the colors in IDLE? I use options-configure IDLE and some of the changes work in my project and some don't. For example, disabling the colors in my find funcion in the editor doesn't use the 'found' attribute when I alter the 'found' highlight colors. It only highlights what is found when I set the foreground and background colors.
I would prefer to edit a file so I know what it is highlighting, such as comments, strings, keywords, etc.
The IDLE Perculator works better than all of the highlight code I tested.
Just been trying to work out how to set the highlight colors to what I want. Either light or dark themes.
Found basic doc. for IDLE but nothing on how to figure out what is what. Only some settings take effect.
I found all of the idlelib source in the appdata folders and put it into my project folder. I know can set the backgrounds in the IDLE shell for the various keywords etc. Looks ok for a dark theme now. When I run or compile I get the colors I set in the IDE in my text (editor) widget. I still have to set the default text colors in my app. When I don't, I get black text on white background which looks terrible in the dark theme.
So a little more work...

Using ttk theme azure-dark and Changing background color of ttk combobox widget

I am using the ttk azure theme dark Azure-ttk-theme. It sets the background color to nice modern looking UI. However, as seen in the images the background color of the tk window, Text widget and combobox widget is set as same. This looks bad when we are using all these together with some text in area(as seen on the right side of screenshot below).
I tried to modify the background of my combobox as below(pardon the full imports- just for replication):
from tkinter import *
from tkinter.ttk import *
root = Tk()
style = ttk.Style(root)
root.tk.call("source", SYSTEM_DIR / "azure.tcl")
root.tk.call("set_theme", "dark")
style.configure("TCombobox", fieldbackground= "orange", background= "white")
g_combo = Combobox(root, style="TCombobox")
But, the above code does not have any effect on my interface. If someone has any idea on how I can handle this. I might have to modify the tcl file for this theme. Since, I have limited knowledge on tcl I am looking for answers/suggestions here.
Ahh, well, I am answering this question because I also tried using this theme yesterday. My idea was too something similar to yours. I wanted to change the default colors and stuff to get a better UI. Before getting into the solution, I have to tell you that this theme overrides the default values and designs to a custom-created one as set by the author. So here's what you can do to achieve what you want.
As far as I know, the only way to do this is to edit the TCL file, which manages the colors of the widgets. It would help if you had some idea about TCL language before you get into it so deep. So I will tell you step by step:
Go to dark.tcl file, and then find the widget's code where you want to change the background color. Say you want to change the combo box's background color. So if you are on windows, you can search "Combobox" by pressing ctrl+f after opening that file (I suggest using Notepad to edit it, it's more accessible).
Ok, so here are the codes where you want to change. As you can see in the third part of the code (ttk::style element create Combobox.field), it is used to create the combo box widget. You can keep trying changing different statements and customize the whole Combobox and its effects (If you know how to). But now lets focus on background color
So in there, you see that the default background is set to an image known as box-basic.
So now you have to go to Azure-ttk-theme/theme/dark folder and find out where that box-basic file is. Once you find it, you have to edit the colors of that image with respecting the same size and then replace the old one and make sure you set the same name. I suggest you to use figma to replicate another image. Its easy. Change it to any color you wish.
And you are done!
With some other theme fieldbackground would work, but not with Azure (or with any of my themes).
Tk handles PNG images containing transparency very badly, especially on Microsoft Windows.
So to reduce lagging, I removed the transparent areas of the image elements, and therefore where you'd expect fieldbackground to be, there's actually the images' background, which looks like as if it were fieldbg.
So the solution is to edit the images, as TechieGeeke suggested.

How to make Tkinter volume slider in a professional way

I'm trying to make a volume controller in python tkinter. But what exactly the problem is that, I want to make it look rich and professional. So when I tried using tkinter scale widget, it worked. But the widget is just a normal one. I wanted to know a way to make it look like the image below I have sent.
My current one's code is this:
def slider(self):
self.scale = scale = ttk.Scale(self.canvas, from_=0, to=100, orient=HORIZONTAL)
print(self.scale.winfo_class())
self.scale.place(x=580,y=455)
self.scale.set(70)
Is there anyway I can make it look better like the one in the Image?
What all things I want is:
A knob like round thing like in the image which is movable
Some color should fill in the area that is already covered.
A pop up or anything to show the current details of the volume.
I'm using pygame to play music in tkinter btw..
If this isn't possible, please suggest me a better way/alternative to do this. Thank you.
As far as I know, there is no existing widget with a look exactly like what you are asking for. However, tkinter provides a way to craft your own widget styles, which might make it possible to do what you want.
Tkinter comes with a module named ttk, which stands for "themed tk". It allows you to define custom styles for individual widgets, and to bundle those styles into a collection known as a theme. If you want to create a widget with a custom look, you can use this module to do so.
Unfortunately, being able to design a custom theme for a widget isn't very well documented. The best documentation I personally know of is on tkdocs.com, in the section Styles and Themes. It gives a pretty good rundown of the terminology and overall description of how themes work. The python documentation for ttk also gives some additional information about creating styles and layouts in a section titled Ttk Styling.
For inspiration, you can check out the code for the ttkthemes project (github, public documentation) which has many different themes that you can examine. I doubt there is one exactly like you want, but you should be able to create your own after looking through the examples.
It is as easy as setting a theme for the TkInter project. Done in Python it looks like that:
s.theme_use('themename')
You might benefit from reading Styles and Themes documentation of TkDocs.

WxPython Choice Field Invisible just on Mac

I am developing a cross platform app in Python using wxPython. The app is fully developed, and the graphics toolkit is set in stone, at least for the time being.
On Windows, everything looks great. On Linux, everything looks pretty good. On Mac, I am having trouble with a combobox/choice being hidden in the toolbar, even though it shows up fine on Windows.
Here is a snapshot of my app on Linux, noting the entire "CoeffConv ..." section is part of the perfectly displayed combobox:
And here is a snapshot of the same exact codebase on Mac:
I've tried with wx.ComboBox and wx.Choice with the same effect. I've made sure to call Realize() after I've added my toolbar items. I've made sure AddControl is called to actually add the object to the toolbar. It's definitely trying to render because the spacing is exactly what I would expect, given the contents of the choice field.
In fact, if I don't call AddControl, but I create the choice field with the toolbar as the parent, the box gets rendered but things aren't arranged properly due to the missing AddControl call:
As another check, I created a super simple toolbar with choice demo, and it works just fine:
So, here's the summary of things I know:
On Windows, the choice field works perfect, indicating the code isn't necessarily wrong.
On Linux, the choice field works perfect, supporting the idea that the code is actually OK.
On Mac, the choice field is present it seems, but somehow invisible, implying this is a problem with the Mac, or the Python distribution on Mac, or the combobox control in the wxPython distribution on Mac.
On Mac, I can get the choice to render (improperly but still) without an AddControl call, indicating the combobox can render properly, but something is goofy about the placement when added to the toolbar
However, On Mac, I can get a toolbar/choice to render totally fine in a dummy example, indicating it's something about my implementation...but I can't figure out what would cause it as I'm trying to make the exact same calls to the wx objects as in the dummy example.
I can't get the dummy example to reproduce the problem, but I'll keep trying. I'm happy to report out some object properties if they would be helpful in diagnosing. If someone has a clue for what could cause it to not show up, I'd really appreciate it!
While I couldn't find the root as to why it didn't work on Mac, I did find an issue that could help others.
First a little more background. In the app, we have multiple toolbars. Because of that, we are creating toolbars using plain wx.ToolBar objects and adding them to the app frame using sizers. This is in contrast to the more standard method of using self.CreateToolBar() which only allows a frame to have a single toolbar.
When I make a single change to the code to use the more natural CreateToolBar interface, the combobox immediately shows up. When I do that, the second toolbar is messed up, but at least the initial toolbar works perfectly. I'll be investigating how to get multiple toolbars on Mac, but it's a step in the right direction.
It's been a while, but there's another solution to this for wxPython 4 if you can't use CreateToolBar():
The widgets do get added to the bar and reserve the correct amount of space, but they fail to draw properly. You can resolve this by calling control.Hide() followed by control.Show() on each widget control, which then makes them draw properly.

In GTK on Windows, how do I change the background color of the whole app?

According to http://www.pygtk.org/docs/pygtk/gtk-constants.html, there are five state types: STATE_NORMAL, STATE_INSENSITIVE, etc. I want to set the background color of a Table, HBox, VBox, whatever, and I've tried setting every possible color of every kind of state:
style = self.get_style()
for a in (style.base, style.fg, style.bg,
style.light, style.dark, style.mid,
style.text, style.base, style.text_aa):
for st in (gtk.STATE_NORMAL, gtk.STATE_INSENSITIVE,
gtk.STATE_PRELIGHT, gtk.STATE_SELECTED,
gtk.STATE_ACTIVE):
a[st] = gtk.gdk.Color(0, 34251, 0)
Nothing has any effect. The only one that has any effect is when I manually created EventBoxes and specifically used the existing gtk.STATE_NORMAL color to blend with other colors. All the ones created by gtk without my intervention were not affected, though.
What's the proper way to go about doing this? I wouldn't mind having to make a gtkrc file or whatever. Is this because hbox, vbox, etc., don't have a color, but are transparent? Who provides the general color of the application, then?
Mostly google-fu (no windows here), posting as an "answer" mostly for a slightly better formatting. See if experimenting with the full-blown gtkrc like the one from here brings the fruits. The location, based on this and this appears to vary - so unless someone has the deterministic approach of finding it, filemon could be a sensible approach.
Being mostly a user for these kinds of apps, I would prefer the settings from my gtkrc over the hardcoded by what the programmer thought would be "the best", anytime.
It's because VBox and Hbox don't have an associated Window.
click here to see other widgets without windows. I would create event boxes and add the HBox or VBox inside the event box.
You need to call self.set_style(style) after changing the style. I used your code as a template and adding that line makes the background of everything green.

Categories