I have created a ttk Notebook with multiple tabs. Each of the tab contains data that user needs to enter. What I would like to do is to change the colour of the tabs, based on a user button click.
Say, initially all the tabs are red. I have an update button for each tab, and when the user clicks this, the tab colour should change to green. I would like the user to know which all tabs are complete, and whch are not.
Is ther any way this is possible? I tried configuring the ttk.Style(), but it affects the entire notebook.
You can simple to it by change the color of the Button
Here is a simple example that can help you
from tkinter import *
root=Tk()
def click():
btn.config(bg='green')
btn=Button(root,text='Update',bg='red',command=click)
btn.pack()
root.mainloop()
Related
I have a ttk notebook with 3 tabs and each tab has a button in the frame. When the button is clicked I want the tab to change to green, signifying that that tab is completed. However, when I look online I can only find ways to apply a ttk style in this way:
s = ttk.Style()
s.theme_use('default')
s.configure('TNotebook.Tab', background="green3")
s.map("TNotebook", background= [("selected", "white")])
which sets the configuration for the entire notebook and changes all of the tab colors. Is there a way to just set one tab permanently to green?
I have a customized button, on which I loaded an icon like this:
but as you can see there's a "box" around the button. The icon itself doesn't have background, so I guess the box is added by tkinter to indicate that this is a button. Is there a way to make those four lines disappear?
Thanks in advance.
Here's an excerpt for a main menu using Python Tkinter
master = Tk()
lbl = Label(master, text = "Main Menu:")
lbl.grid(row=0,column=1)
def list():
import list
listb = Button(master, text = "Patient List", command=list, width=10)
listb.grid(row=1, column=1)
There's a button "Patient List" that when pressed, opens a window specified from a different python file.
My problem is that the Main Menu window suffers a bug where the window will collapse. The new window comes out fine, but after closing it, I can't use my Main Menu.
Also, on my other buttons. The Main Menu doesn't collapse, but let's say I have a button Add Patient and after clicking it, the Add Patient window appears. It's functional. And then I close it, either using the quit button I programmed in it, or the close button. The Main Menu won't open the Add Patient window again.
So how can I smoothly navigate from one python program to another? Without the main menu collapsing. While being able to open a window over and over again.
My Patient List program has a lot of customized gui programming in it. I think it's because I use a grid in my Main Menu, and it's not a grid in my Patient List. But it shouldn't be affecting the Main Menu because they're supposed to be separate programs.
When doing such program with TKinter I generally use Screen classes.
To your example it would be for example:
"MainScreen", "AddPatienScreen", ...
All are subclass of the Frame tkinter class.
My Tk app only display one screen and furnish function to destroy and replace one screen by another one.
I have not access to any code now, but I invite yourself to try this approach if you understand it. It lead to well separated code and had good results.
I may provide you a very short example if required.
I am using Tkinter for my python script. At current stage, gui looks ugly because of too many options/widgets in one screen. Not all of them are needed all the time and it can be divided into four parts. Hence my idea is to have them expand the frame (one frame for each part) with its options/widgets in the current window.
Is it possible in tkinter to expand the window/frame when a button or a checkbox is clicked?
ps - I have tried opening each part in new window but this makes gui unnecessarily complicated.
Thanks!
So, your gonna need to define what happens when the button is clicked-
def buttonClicked():
root.geometry("350x300")
where root is the window and then on the button you will need to write -
btn = tkinter.Button(text = "Button", command=buttonClicked)
btn.pack
Hope that answers your question!
When a user selects a portion of text in a Tkinter Entry widget it becomes highlighted. However, when the user clicks away from the widget the highlighting disappears.
Is there any way to keep the selected text highlighted despite the Entry widget not having focus?
I'm attempting to make a custom right-click menu not based on the Tkinter Menu widget (it's based on a Tkinter Toplevel widget), and I would like the text to remain highlighted despite the menu having focus.
You want to set the exportselection option of the text widget to False
text_widget.configure(exportselection=False)