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.
Related
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.
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.
I am currently building a simple app to encrypt files using AES encryption in python but the biggest downside of using Tkinter is the look of the UI. I did some research and found examples of what I want but do not know how to recreate it. (Example)
My problem is that when I replace buttons with images (like the OP of the Reddit post said he did in order to have a decent looking UI) I end up with an ugly bar of grey. (Image of the button)
I also want to remove the same type of bar with frames so if you have the answer for specifically that it would still be appreciated.
Support for for styles and themes has existed in tkinter for some time. A theme being a collection of styles for different widgets.
You can read more about style and themes here.
To the best of my knowledge, the standard widgets to not support rounded corners. All widgets have rectangular shapes.
You might be able to create something like that using a Canvas, but it would be a significant amount of work.
A more relevant point is that it might confuse your users if you don't reproduce the way the standard controls work.
UI elements are standardized for the same reason the controls in a car are; once you know one of them you can use all of them.
Is there an easy way to style UI written in python using Tkinter? I need to turn something very basic like this:
Into something styled and more fancy looking like this:
Is there a drag, drop and resize tool that can help me build the UI quickly and efficiently?
Use the ttk widgets. Those are themed.
You can find example of tile (bitmap) based themes here.
Not being a tcl expert, I'm not sure you to get tcl/tk to recognize and load these themes. But here are some pointers.
I am trying to build a Kivy application with a sharp, crisp look and feel but the default Kivy UI is not exactly what I had in mind? Is there any way to create a custom theme to give your Kivy app style?
This app here is called Pithon and it was made from Kivy. I have searched everywhere but I can not find anything on how the developer managed such a clean look. Does anyone have any ideas?
A kivy developer called Andrés Rodríguez released a set of widgets based on google's material design principles. I am currently using them myself and they have surely saved me from alot of work. You can find KivyMD here (see bottom of this answer for more info). Their are some themes also based on the same principles but am yet to try them out one is FlatKivy and another is kivy material ui by Federico Curzel.
Some screenshots for kivyMD,flatkivy and kivy material ui respectively are here.
Click the highlighted links you will find a lot more info about the three projects.
The original KivyMD project by Andrés Rodríguez is no longer maintained but there is active fork of KivyMD by HeaTTheatR.
(Almost) all widgets have properties that can be used to set aspects of their style. For instance, with a Button you can change the background colour, the background image when pressed or released, and the size of the border region (it's scaled like in CSS border images). You can check the documentation for the specifics of a given widget.
An theme like in the screenshot you posted could be achieved by turning off background images for the buttons and just using solid colours, with the non-button text being normal Labels and the circle being drawn directly with a kivy canvas instruction or via an Image widget (along with an image of the circle).
I notice you mentioned padding in a comment but I'm not sure what you mean by it - do you mean the distance between the buttons? They may well be placed in a GridLayout which has a padding property controlling this, so you could set it to whatever you like.
I recognise that you're asking a more general question than 'how does this screenshot do it?', but the key point is that just about everything is customisable and it doesn't take many changes to go from the default theme to your image.
Edit: One useful feature that helps this kind of customisation is that you can use kv language to override styles for widget classes very easily, so you don't need to manually change every button etc.