fill attribute of pack in tkinter is not working - python

I am trying to keep the title in centre when resizing the window
I tried to change the label and to import * modules from tkinter for possible solution
Any help or hint is highly appreciated
following is the attached code:
import tkinter as t
root=t.Tk()
root.geometry("1000x500")
'''Login/Register page '''
root.title("LOGIN PAGE")
bankLabel=t.Label(text="Bank of DINAGOD")
bankLabel.pack(fill='x')
bankLabel.place(x=475)
root.mainloop()

You can't use both pack() and place() function on the same widget. Use only pack() function to declare the positions of your widget.

Related

How to Design the Scrollbar in tkinter (not ttk ones)

I have tried to design the tkinter's Scrollbar instead of using ttk ones.
But I couldn't be able to implement designs on the scrollbar. I think I have implemented the same config options as in the effbot docs.
from tkinter import *
testing=Tk()
a=Listbox(testing,height=6)
sc=Scrollbar(testing,orient=VERTICAL,command=a.yview)
for i in range(100):
a.insert(END,i)
a.config(yscrollcommand=sc.set)
def designs():
# This function does nothing :(
sc.config(background='orange',borderwidth=34)
sc.config(highlightthickness=30,highlightcolor='orange',highlightbackground='skyblue')
sc.config(troughcolor='orange')
designs() # here...
sc.pack(side=RIGHT,fill=Y)
a.pack()
testing.mainloop()
is there a way to change the background color of the trough part and non-trough part of the scrollbar and some effects like the active background? Please Help!!!

Is it possible to fit a special size for tkinter window?

I use tkinter in python and I want to fix the size of a window in tkinter for always it means that if user wants to change it by restore button the window size not changed.
from tkinter import *
root=Tk()
root.geometry("1800x900")
root.mainloop()
I'm not sure I've fully understood your question, but to enforce a fixed window size I've used to set min and max to the same value, as follows.
from Tkinter import Tk
root=Tk()
fixed_geometry=180,90
root.minsize(*fixed_geometry)
root.maxsize(*fixed_geometry)
root.mainloop()

How do you put multiple tkinter widigets into one .grid

I am trying to make a date chooser using python. I am using spinboxes, however I was wondering whether I could get all 5 widgets into one grid space, so it seemed like all 5 widgets are really one widget. Hopefully the following code articulates the problem better.
import tkinter as tk
root=tk.Tk()
Day=tk.IntVar()
Month=tk.IntVar()
Year=tk.IntVar()
Label1=tk.Label(root,text="Label Label Label Expanding Row")
Label1.grid(row=1,column=1)
DayEntry=tk.Spinbox(root,textvariable=Day,bg="white",from_=0, to_=31,width=2)
DayEntry.grid(row=2,column=1)
MonthEntry=tk.Spinbox(root,textvariable=Month,bg="white",from_=0, to_=12,width=2)
MonthEntry.grid(row=2,column=3)
YearEntry=tk.Spinbox(root,textvariable=Year,bg="white",from_=2000, to_=20019,width=4)
YearEntry.grid(row=2,column=5)
Divider1=tk.Label(root,text="/")
Divider1.grid(row=2,column=2)
Divider2=tk.Label(root,text="/")
Divider2.grid(row=2,column=4)
root.mainloop()
The solution is to put all of the widgets in a frame.
datepicker = tk.Frame(root)
datepicker.grid(row=2, column=0)
DayEntry=tk.Spinbox(datepicker,textvariable=Day,bg="white",from_=0, to_=31,width=2)
MonthEntry=tk.Spinbox(datepicker,textvariable=Month,bg="white",from_=0, to_=12,width=2)
YearEntry=tk.Spinbox(datepicker,textvariable=Year,bg="white",from_=2000, to_=20019,width=4)
Divider1=tk.Label(datepicker,text="/")
Divider2=tk.Label(datepicker,text="/")
DayEntry.grid(row=0,column=1)
Divider1.grid(row=0,column=2)
MonthEntry.grid(row=0,column=3)
Divider2.grid(row=0,column=4)
YearEntry.grid(row=0,column=5)

How do I style a ttk.LabelFrame, specifically the background color?

I am trying to add some custom styling to a ttk.LabelFrame. My code looks like this:
root=Tk()
style = ttk.Style()
style.configure('TLabelFrame', background='SystemWindow')
style.configure('TFrame', background='SystemWindow')
The ttk.Frame styling works so I am not sure what is different here.
Edit: Also how can I style the label in the LabelFrame?
For anyone that views this line 2 in the code above should read style.configure('TLabelframe', background='SystemWindow'). I found a similar question here. Cheers!
Set style for Checkbutton or Labelframe in python tkinter
For someone who just want to set the background color of LabelFrame, You just add your color's code( your can search on google like: grey color code you will get the code: #808080) in background="", this is my code:
frame = LabelFrame(root, text="test", background="#808080")
frame.grid(padx=50, pady=25)
Check all the tutorials related tkinter here. https://www.tutorialspoint.com/python/python_gui_programming.htm
Surely you will get the answer and use Place() method to position your elements in tkinter main frame

How to move the entire window to a place on the screen (Tkinter, Python3)

The title says it all. How to move the entire window to a place on the screen using tkinter. This should be moving the root frame.
Use the geometry method of the root (or any Toplevel) window. For example:
import tkinter as tk
root = tk.Tk()
root.geometry("+200+400") # places the window at 200,400 on the screen
use this:
from tkinter import Tk
main=Tk()
main.geometry('+100+200')
main.mainloop()
or do it with function :
def change_position(root_variable,x,y):
root_variable.geometry('+{}+{}'.format(x,y))
and use :change_position(main,500,400)
edit: added dot for format

Categories

Resources