tix.balloon auf tkinter widget anwenden

Fragen zu Tkinter.
Antworten
zappa
User
Beiträge: 26
Registriert: Samstag 19. März 2011, 22:31

Hallo,
ich würde gerne einen tix.Balloon auf meine tkinter-widgets anwenden; leider meckert Python da.

Code: Alles auswählen

import tkinter as tk
from tkinter import tix

'''hier kommt der Code'''


Traceback (most recent call last):
  File "C:\Python32\ballon.py", line 70, in <module>
    mein_balloon = tix.Balloon(main)
  File "C:\Python32\lib\tkinter\tix.py", line 544, in __init__
    TixWidget.__init__(self, master, 'tixBalloon', static, cnf, kw)
  File "C:\Python32\lib\tkinter\tix.py", line 322, in __init__
    self.tk.call(widgetName, self._w, *extra)
_tkinter.TclError: invalid command name "tixBalloon"
Offensichtlich hat tix das Problem, dass dann alle widgets in tix geschrieben sein müssen - oder kennt jemand eine Möglichkeit?
Ene Uran
User
Beiträge: 125
Registriert: Sonntag 17. September 2006, 20:14
Wohnort: Hollywood

Versuch doch mal dieses einfaches Beispiel ...

Code: Alles auswählen

''' Tix_TixBalloonTest1.py
Tkinter extension module tix comes with Python27 and Python3
tix has addtional widgets like ...
tix.Balloon (acts like tooltip)
see for instance C:/Python32/Lib/tkinter/tix.py for details
'''

try:
    import Tix as tix  # Python27
except ImportError:
    import tkinter.tix as tix  # Python31+

root = tix.Tk()

def hello():
    #label['text'] = 'Hello World'
    label.config(text='Hello World')

def bye():
    label['text'] = 'Bye Cruel World'

status = tix.Label(root, width=40, relief=tix.SUNKEN, bd=1)
label = tix.Label(root, width=40, relief=tix.SUNKEN, bd=1)
btn1 = tix.Button(root, text="Hello", command=hello)
btn2 = tix.Button(root, text="Bye", command=bye)

# create balloon (tooltip) instance
# satusbar is optional
balloon = tix.Balloon(root, statusbar=status)

# bind balloon to buttons
balloon.bind_widget(btn1, balloonmsg='Click to show Hallo',
    statusmsg='optional status1')
balloon.bind_widget(btn2, balloonmsg='Click to show Bye',
    statusmsg='optional status2')

# layout, stack vertically
label.pack()
btn1.pack(pady=8)
btn2.pack(pady=8)
status.pack()

root.mainloop()

Atomkraftwerkaktienbesitzer
zappa
User
Beiträge: 26
Registriert: Samstag 19. März 2011, 22:31

Hallo Ene Uran,
vielen Dank für Deinen Code.
Mein Problem ist aber, dass ich ein recht umfangreiches Programm geschrieben habe, dass auf reinem tkinter basier, also

Code: Alles auswählen

root= tkinter.Tk()
Nun alles auf Tix umzuschreiben wäre echt eine mühsame Sache, da einige Labels, LabelFrame, Notebook dort anders behandelt werden. Ich hatte auf eine Balloon-Möglichkeit in reinem tkinter gehofft.
Antworten