How can I change the text of a Python 3.5 tkinter Notebook tab programatically AFTER adding it to the notebook?
So I have added a tab with:
notebookWidget.add (tabWidget, text = 'myOldText')
which works fine.
Now, I want to do something like:
tabWidget.text = 'myNewText'
or, (more tkinter'ish?):
tabWidget ['text'] = 'myNewText'
Found it:
notebookWidget.tab (tabWidget, text = 'myNewText')
Correct answer is (where tab_idx is the 0 based index of the tab within the notebokk):
notebook_widget.tab(tab_idx, text='Another text')
There is a basic method inherited from Widget which is called configure() and does the job you expect:
tabWidget.configure(text = 'myNewText')
Related
I'm trying to make a text editor app with python Tkinter and tabs with the notebook function. I have 1 problem, when I add the input text box to the screen it works perfectly I tried writing with it and yes it worked, but when I switched to another tab the same text is there and I tried multiple solutions like functions that make another input and if statements, I also saw a StackOverflow post that showed how to use if statements (I don't have the link) but it still didn't work for me.
here is my code :
nb = ttk.Notebook(window)
tab1 = ttk.Frame(nb)
tab2 = ttk.Frame(nb)
nb.add(tab1, text ='Tab 1')
nb.add(tab2, text ='Tab 2')
nb.pack(expand = 1, fill ="both")
ttk.Label(tab1)
ttk.Label(tab2)
editor_text_box = Text(
window,
height=12,
width=40
)
editor_text_box.pack()
You're not putting the text widget in a frame, you're putting it in the parent of the notebook.
If you want a widget to appear in a tab, it must be a child of the frame for that tab.
editor_text_box = Text(tab1, ...)
Im trying to change label text property of Label in Pygubu GUI builder for Tkinter with code:
fps_lable = self.builder.get_object('FPS_Label')
txt = fps_lable.cget('text')
print(txt)
fps_lable.config(text='hello')
But nothing happens. I get the text from label and it prints out (txt var) but when trying to change the text to "hello"... no joy.
Any ideas why ?
Try
fps_lable = self.builder.get_object('FPS_Label')
fps_lable.set('hello') # sets label to 'hello'
NOTE: FPS_Label must be the name of the 'textvariable' for the label in the gui.
I'm having trouble trying to create Table of Contents objects in a PDF file. I'm not sure whether I've understood the process from Apple's limited documentation.
I'm using python, but cogent examples in any language are welcome to explain how it's supposed to work. The code creates a new PDF document, but there's no outline item visible in Preview. I've tried just using myOutline as the root object, but that doesn't work either.
pdfURL = NSURL.fileURLWithPath_(infile)
myPDF = Quartz.PDFDocument.alloc().initWithURL_(pdfURL)
if myPDF:
# Create Destination
myPage = myPDF.pageAtIndex_(1)
pagePoint = Quartz.CGPointMake(0,0)
myDestination = Quartz.PDFDestination.alloc().initWithPage_atPoint_(myPage, pagePoint)
# Create Outline
myOutline = Quartz.PDFOutline.alloc().init()
myOutline.setLabel_("Interesting")
myOutline.setDestination_(myDestination)
# Create a root Outline and add the first outline as a child
rootOutline = Quartz.PDFOutline.alloc().init()
rootOutline.insertChild_atIndex_(myOutline, 0)
# Add the root outline to the document and save
myPDF.setOutlineRoot_(rootOutline)
myPDF.writeToFile_(outfile)
EDIT: Actually, the outline IS getting saved to the new file: I can read it programmatically, and it appears in Acrobat as a Bookmark; however, it doesn't show up in Preview's Table of Contents (yes, I checked for the "Hide" thing). If I add another Bookmark in Acrobat, then both show up in Preview.
So I guess that either I'm still doing something wrong which doesn't quite 'finish' the PDFOutline data properly, and Acrobat is being kind; or there's a massive bug in PDFKit that means you can't write PDFOutlines properly. I get the same behaviour on Mountain Lion, FWIW.
This does appear to be a bug in Preview. It will not list the Table of Contents if it contains ONLY ONE child entry.
If I add more Outlines with the code above, then all of them appear in Preview. If use other software to remove all but one entries in the Table of Contents, then Preview will not show any.
I'm trying to use HwndWrapper.Texts() which supposedly "Returns the text for each item of this control" but it only returns the tile which is u'Fight plan settings dialog', why is this happening?
The code is this:
prog=application.Application()
prog.connect_(path=r'D:\Thesis\Euroscope\Euroscope.exe')
w_handle = pywinauto.findwindows.find_windows(title=u'Fight plan setting dialog', class_name='#32770')[0]
window = prog.window_(handle=w_handle)
c=prog.Fightplansettingsdialog.Texts()
Here is a screen of the window I'm trying to copy from:
http://imageshack.us/photo/my-images/802/newpicturewe.png/
I spent the afternoon reading the pywinauto documentation and i can't manage to find a way to get the content of a window like the one before into a text file(except clicking and copying each item with DoubleClick() and then Ctrl+C with TypeKeys which is way too long). Any ideas?
Edit: Also, I found out that PrintControlIdentifiers can't be easily saved to a strings file. Doing c=prog.PrintControlIdentifiers() returns None when i ask for c. Any way around this?
Thank you
You may get all texts from a window by running through all children.
all_texts = []
for child in window.Children():
all_texts.extend(child.Texts())
all_texts = filter(lambda t:t, all_texts) # clear empty texts
By the way, it seems the window should be called 'Flight plan...' :-)
PS.
I am happy to help a virtual controller!
UKHH - MDN91
I am doing a simple file browser in python and GtkBuilder. I am using a Treeview that has one TreeViewColumn with cells that are rendered like:
self.cell = gtk.CellRendererText()
As I mentioned I am creating a file browser. So I want to have a small icon before the text in each cell, that icon will be the folder,file icon. Any idea on how can I do that?
You don't need to extend CellRendererText, you can insert more than one CellRenderer per column using gtk.TreeViewColumn.pack_start().
You will want to have a CellRendererPixbuf to the left of your CellRendererText.