-1

I've found out how to create a replacement logo for Tk, and to remove the Tk from the window. I have not however been able to find any existence on how to sticky any buttons or such. I've tried creating a class, and a def create_widget, but for some reason I'm getting errors in PyDev debugging. It keeps saying sticky = N + E is undefined. I thought importing ttk would automatically allow me to edit these buttons via self, but when I do self I have to change everything around and then the imports won't allow root. I believe this problem is because I'm not importing the right way, due to the fact I have replaced the logo and removed tk. My question is, how does .pack work and is there something I'm missing majorly in this code?

from tkinter import ttk
import tkinter
import tempfile

ICON =     (b'\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x08\x00h\x05\x00\x00'
    b'\x16\x00\x00\x00(\x00\x00\x00\x10\x00\x00\x00 \x00\x00\x00\x01\x00'
    b'\x08\x00\x00\x00\x00\x00@\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
    b'\x00\x01\x00\x00\x00\x01') + b'\x00'*1282 + b'\xff'*64

_, ICON_PATH = tempfile.mkstemp()
with open(ICON_PATH, 'wb') as icon_file:
    icon_file.write(ICON)


root = tkinter.Tk()

buttonstyle = ttk.Style()
buttonstyle.map("C.TButton",
    foreground=[('pressed', 'red'), ('active', 'blue')],
    background=[('pressed', '!disabled', 'black'), ('active', 'white')]
    )
colored_btn = ttk.Button(text="Activate", style="C.TButton").pack()

b = ttk.Button(root, text='Rename')
b.pack()

style = ttk.Style()


style.theme_settings("default", {
   "TCombobox": {
       "configure": {"padding": 5},
       "map": {
           "background": [("active", "green2"),
                          ("!disabled", "green4")],
           "fieldbackground": [("!disabled", "green3")],
           "foreground": [("focus", "OliveDrab1"),
                          ("!disabled", "OliveDrab2")]
       }
   }
})

combo = ttk.Combobox().pack()

style.layout("TMenubutton", [
   ("Menubutton.background", None),
   ("Menubutton.button", {"children":
       [("Menubutton.focus", {"children":
           [("Menubutton.padding", {"children":
               [("Menubutton.label", {"side": "left", "expand": 1})]
           })]
       })]
   }),
])

mbtn = ttk.Menubutton(text='Rename')
mbtn.pack()

root.title("Rename")
root.iconbitmap(default = ICON_PATH)

root.geometry("700x300")

label = ttk.Label(root, text = "Rename")
label.pack()

root.mainloop()
mydiax
  • 41
  • 10
  • I've looked on Google, Python Doc 3.5, and youtube. But every support is not saying anything about how to .grid(row = ... ) on a .pack – mydiax Oct 09 '15 at 23:24
  • "how does pack work" is way too broad for stackoverflow, and "how to .grid... on a .pack" makes no sense. Grid and pack are two different ways to accomplish the same task. It's like grilling vs frying, or driving a car vs driving a bus. You can't "grill on a fry" or "drive a car on a bus". You might want to start by reading http://effbot.org/zone/tkinter-geometry.htm – Bryan Oakley Oct 10 '15 at 00:23

1 Answers1

1

Take a look at your imports:

from tkinter import ttk
import tkinter
import tempfile

Now look at the sticky code that reportedly failed:

sticky = N + E

The references N and E (which are just 'n' and 'e') are in tkinter, so you'll need to access them like other objects in that package, with the tkinter. prefix:

sticky = tkinter.N + tkinter.E

or just use a literal string:

sticky='ne'
TigerhawkT3
  • 48,464
  • 6
  • 60
  • 97
  • Could you show me an example on `b = ttk.Button(root, text='Rename') b.pack()` on a description the .grid(row =... looks? – mydiax Oct 09 '15 at 23:50
  • @mydiax - Are you using `grid` and `pack` together? – TigerhawkT3 Oct 09 '15 at 23:56
  • Not really sure how it's suppose to look, I got the code for replace logo Tk on here using the same imports, then went to ttk. So I went to Python 3.5 Docs, and it uses .pack, so I guess I'm using .pack. I started off using Tkinter following tutorials and learned how to .grid and create class Application(Frame), and root.mainloop, so I know how to self with the regular Tkinter, but not with ttk, what I'm trying to say is that I'm not really sure what to do with the `.pack` and Python Docs doesn't say anything about it either in ttk. – mydiax Oct 10 '15 at 00:00
  • Combined with your comment above about "using grid on a pack" which doesn't make any sense, it sounds like you need to do some significant research here. I recommend the [docs on Effbot](http://effbot.org/tkinterbook/). – TigerhawkT3 Oct 10 '15 at 00:02