7 Replies - 5675 Views - Last Post: 29 January 2016 - 03:11 PM Rate Topic: -----

#1 whoisit   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 66
  • Joined: 15-October 08

Button options

Posted 29 January 2016 - 01:07 AM

Below is the code for a button
btn_press = ttk.Button(mainframe, width=30, text="Press Here", command=tell_fortune).grid(column=0, row=3, sticky=W)


When I try bg= or fg= or height= I get an error unknown.

Why is this? the button in the code above works until I try adding one of the above commands.

Thanks for looking.
Is This A Good Question/Topic? 0
  • +

Replies To: Button options

#2 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6831
  • View blog
  • Posts: 28,337
  • Joined: 12-December 12

Re: Button options

Posted 29 January 2016 - 02:04 AM

What is the exact error message?
Was This Post Helpful? 0
  • +
  • -

#3 whoisit   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 66
  • Joined: 15-October 08

Re: Button options

Posted 29 January 2016 - 10:10 AM

Its a lot!
Traceback (most recent call last):
File "C:\Users\anybl\My_Python\Fortune_Teller.py", line 38, in <module>
btn_press = ttk.Button(mainframe, width=30, bg='#ffff00', text="Press Here", command=tell_fortune).grid(column=0, row=3, sticky=W)
File "C:\Users\anybl\AppData\Local\Programs\Python\Python35-32\lib\tkinter\ttk.py", line 608, in __init__
Widget.__init__(self, master, "ttk::button", kw)
File "C:\Users\anybl\AppData\Local\Programs\Python\Python35-32\lib\tkinter\ttk.py", line 553, in __init__
tkinter.Widget.__init__(self, master, widgetname, kw=kw)
File "C:\Users\anybl\AppData\Local\Programs\Python\Python35-32\lib\tkinter\__init__.py", line 2138, in __init__
(widgetName, self._w) + extra + self._options(cnf))
_tkinter.TclError: unknown option "-bg"

Below is all the code in case something else is conflicting with it.

from tkinter import *
from tkinter import ttk
import random

fortunes = [
    "2016 is your Lucky year!", "Good fortune is coming your way.", 
    "Better stay in today", "Love is on the horizon", 
    "Whatever will be will be.",
]

def tell_fortune(): #Update Label Text
    r = random.randint(0,4)
    result.set(fortunes[r])

    
window = Tk()
window.title("Fortune Teller")
window.wm_iconbitmap('fortuneicon.ico')
window.geometry('400x200') # Fixed window Size 400, 200
    

mainframe = ttk.Frame(window, relief='groove', borderwidth=5, padding='12 12 12 12')
mainframe.grid(column=0, row=0)
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)

img = PhotoImage(file='header.gif')


result = StringVar()
result.set('')

lbl_Header = ttk.Label(mainframe, image=img).grid(columnspan=3, row=0, sticky=(W,E))
lbl_fortune = ttk.Label(mainframe, textvariable=result).grid(columnspan=3, row=1)

pb = ttk.Progressbar(mainframe,orient='horizontal',length=300,mode='determinate', maximum=100, value=4).grid(columnspan=3,row=2, sticky=(W,E))

btn_press = ttk.Button(mainframe, width=30, bg='#ffff00', text="Press Here", command=tell_fortune).grid(column=0, row=3, sticky=W)
btn_quit = ttk.Button(mainframe, text="Quit", command=exit).grid(column=1, row=3, stick=E)

for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)


window.mainloop()



Was This Post Helpful? 0
  • +
  • -

#4 CurlyJoe   User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 97
  • Joined: 19-September 13

Re: Button options

Posted 29 January 2016 - 11:18 AM

ttk buttons don't use "bg", etc. it uses "styles". A tutorial, but not a great one http://www.tkdocs.co...ial/styles.html If you find a better example page please let us know.

This post has been edited by CurlyJoe: 29 January 2016 - 11:21 AM

Was This Post Helpful? 0
  • +
  • -

#5 whoisit   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 66
  • Joined: 15-October 08

Re: Button options

Posted 29 January 2016 - 01:03 PM

Thanks Joe, you're right about that tutorial it's as clear as mud.
Was This Post Helpful? 0
  • +
  • -

#6 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6831
  • View blog
  • Posts: 28,337
  • Joined: 12-December 12

Re: Button options

Posted 29 January 2016 - 01:51 PM

Not a tutorial, but New Mexico Tech reference material is very good.

47. Customizing and creating ttk themes and styles

Some of the modules may be referenced as Python 2.* versions, there is a list of the different module names here, which is a handy reference.
Was This Post Helpful? 0
  • +
  • -

#7 whoisit   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 66
  • Joined: 15-October 08

Re: Button options

Posted 29 January 2016 - 02:53 PM

Thanks Andrew, will take a look at the links.
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6831
  • View blog
  • Posts: 28,337
  • Joined: 12-December 12

Re: Button options

Posted 29 January 2016 - 03:11 PM

I have a tutorial myself which may be of interest:

Tkinter Overview, With A Fixed-Width Grid

(No custom styles, but it is a fuller project using a number of widgets.)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1