Python Tkitner : unknown option "-height". Can't change the size of button
This is one of the prime examples of why global imports are bad.You write at the top:
from tkinter import *from tkinter.ttk import *
This means that you import everything from tkinter
and tkinter.ttk
into your main.py
namespace. Then you write for example:
frame3 = Frame(self, bg="grey")....lblCol = Label(frame2, text="Column", width=7)
These are Frame/Label objects, but which ones? The one in tkinter
or the one in tkinter.ttk
? If it is the first, you will have to set the height with -height
, else you will have to use tkinter.ttk.Style()
. Same with the -bg
for the frame.
Solution:
import tkinter as tkclass Example(tk.Frame): def __init__(self,master): super().__init__() master.minsize(width=350, height=160) master.maxsize(width=650, height=500) self.initUI() def initUI(self): self.master.title("Hank (version 3)") self.pack(fill=tk.BOTH, expand=True) frame1 = tk.Frame(self) frame1.pack(fill=tk.X) #dataset lbl1 = tk.Label(frame1, text="Dataset file_name", width=18) lbl1.pack(side=tk.LEFT, padx=5, pady=5) entryDataset= tk.Entry(frame1) entryDataset.pack(fill=tk.X, padx=5, expand=True) #row col begin frame2 = tk.Frame(self) frame2.pack(fill=tk.X) lblRow = tk.Label(frame2, text="Row", width=6) lblRow.pack(side=tk.LEFT, padx=5, pady=5) entryRow = tk.Entry(frame2, width=5) entryRow.pack(side=tk.LEFT, padx=0, expand=True) lblCol = tk.Label(frame2, text="Column", width=7) lblCol.pack(side=tk.LEFT, padx=5, pady=5) entryCol = tk.Entry(frame2, width=5) entryCol.pack(side=tk.LEFT, padx=5, expand=True) lblBegin = tk.Label(frame2, text="Start at", width=6) lblBegin.pack(side=tk.LEFT, padx=5, pady=5) entryBegin = tk.Entry(frame2, width=5) entryBegin.pack(side=tk.LEFT, padx=0, expand=True) frame3 = tk.Frame(self, bg="grey") frame3.pack(fill=tk.BOTH, expand=True) frame4 = tk.Frame(self) frame4.pack(fill=tk.BOTH, expand=True) startbutton = tk.Button(frame4, text="Start Clustering", height="100", width="100") startbutton.pack(side=tk.RIGHT, padx=5, pady=5)def main(): root = tk.Tk() root.geometry("300x160+300+160") app = Example(root) root.mainloop()if __name__ == '__main__': main()
I did it here with the tkinter
widgets. You can obviously do import tkinter.ttk as ttk
and rewrite the code using those, it is just a matter of taste.