Python - open file and display on screen - python-3.x

I was trying to write a program. I'm using tkinter and I've created a label and a menu bar. I would like to open a PDF from the menu bar (HELP --> Instruction for use), but I don't know how. I've tried the module filedialog.askopenfile but it is not appropriate for me because I want to dispay a specific PDF on screen and not browse through them.
Here is the code for the menu bar:
subMenu = Menu (menubar, tearoff = 0)
menubar.add_cascade (label = "Help")
subMenu.add_command (label =" Instruction for use", command = help)
def help ():

Related

PyQt5 how to show output on the GUI without clicking buttons

Can someone please tell me How can i show the Mac address value without clicking the button, i would be able to type in the "Scancode Gehäuse" value and the mac address should update immediately without me clicking the button.
I need to cut and dissect the "Scancode Gehäuse" value to get the mac address as shown below as code:
self.ui.button_TestStartenVA.clicked.connect(self.split_scancode_string)
def split_scancode_string(self):
self.scancode_gehause = self.ui.lineEdit_SCGehauseVA.text()
self.scancode_gehause_mac = self.scancode_gehause[12:]
self.scancode_gehause_artikel = self.scancode_gehause[:5]
self.scancode_gehause_mac = ':'.join(self.scancode_gehause_mac[i:i+2] for i in range(0, len(self.scancode_gehause_mac), 2))
self.ui.lineEdit_MACVA.setText(self.scancode_gehause_mac)
self.ui.ArtikelNummerlineEditlVA.setText(self.scancode_gehause_artikel)

How to provide dropdown submenus inside one tray menu as below shown in image using pystray library in python?

Here is my sample code:
image = Image.open("E:\\production\\Windows utility tool\\images\\icon.ico")
menu = (item("Sign in", show_window), item("Change status", status_online), item("Change icon", change_icon), item("Open application", open_application), item("Quit", quit_window))
icon = pystray.Icon("Notifer", image, "notifier_application", menu)
icon.run()
See sample image
This is how the menu should be for drop down submenus
menu = (
Item('mainitem1', callable),
Item('mainitem2', callable),
Item('mainitem3', Menu(Item('subitem1', callable),Item('subitem2', callable))),
Item('mainitem4', callable)
)
Make sure to add from pystray import Menu, MenuItem as Item at the beginning of the code.
Hope I gave you a proper answer.

Listbox resizing itself when new data is added

I am trying to add information to my Listbox and keeping it the size I state when I configure it. Here is my code for the Listbox with the scrollbar and an image of what it looks like.
Picture of the listbox.
taskList = Listbox(setBox, bg="#1B2834",fg="white")
taskList.configure(width=183,height=39)
taskList.pack(side=LEFT,fill=BOTH)
taskScroll = Scrollbar(setBox)
taskScroll.configure(bg="#1B2834",width=18)
taskScroll.pack(side = RIGHT, fill = BOTH)
taskList.config(yscrollcommand = taskScroll.set)
taskScroll.config(command = taskList.yview)
Now, when i click a button the command is to execute this following code:
def savetasks():
#make tasks
letters = string.ascii_uppercase
result_str = ''.join(random.choice(letters) for i in range(4))
num = str(random.randrange(0,9))
taskIDnum = num+result_str
taskIDLBL = Label(taskList, text=taskIDnum,bg="#1B2834", fg="White")
taskIDLBL.configure(padx=20,pady=10)
taskIDLBL.pack()
This code works fine as well, creating new labels with a random ID but it resizes the listbox to look like this...
Picture of the list box after clicking the button to execute the command.
Lastly, the scroll bar is not scrollable and when I create a lot of id's that end up going off my screen I cannot use the scroll bar to scroll down to see them, is there a way to not let the Listbox be resized and is it possible to set the Listbox with max and min-height?
If there is an easier way to do this without using a Listbox please let know, I just need to able to scroll down to see all the other id's and I didn't see any other way to use a scroll bar, that I NEEDED to use a Listbox

tkinter treeview: how to disable widget?

We're building a GUI interface with Python+tkinter.
The problem is when we want to set the view mode of an entity. I need to set the view mode or state of the treeview widget as 'disabled'.
How can we solve it?
Thanks for any support.
UPDATE
self.frmTab01.trvDetailorder.configure(selectmode='none')
I'm looking for a solution in which appart from disable the selection, affect the visualization of the widget just like an entry widget.
nbro is right, you need to change the Treeview style to make it look disabled. In addition, I also deactivated the possibility to open/close items when the Treeview is disabled using binding tricks on the mouse click.
In my example I added an entry so that you can compare the look on the two widgets. If you are using OS X or Windows, you might need to change the theme (style.theme_use("clam") should do) because their default themes are not very customizable.
from tkinter import Tk
from tkinter.ttk import Treeview, Style, Button, Entry
root = Tk()
def toggle_state():
if "disabled" in tree.state():
e.state(("!disabled",))
tree.state(("!disabled",))
# re-enable item opening on click
tree.unbind('<Button-1>')
else:
e.state(("disabled",))
tree.state(("disabled",))
# disable item opening on click
tree.bind('<Button-1>', lambda e: 'break')
style = Style(root)
# get disabled entry colors
disabled_bg = style.lookup("TEntry", "fieldbackground", ("disabled",))
disabled_fg = style.lookup("TEntry", "foreground", ("disabled",))
style.map("Treeview",
fieldbackground=[("disabled", disabled_bg)],
foreground=[("disabled", "gray")],
background=[("disabled", disabled_bg)])
e = Entry()
e.insert(0, "text")
e.pack()
tree = Treeview(root, selectmode='none')
tree.pack()
tree.insert("", 0, iid="1", text='1')
tree.insert("1", 0, iid='11', text='11')
Button(root, text="toggle", command=toggle_state).pack()
root.mainloop()

How to verify whether a blinking cursor is currently inside of a text box through TestComplete

I am trying to verify that the text box gets the focus (the blinking cursor gets placed inside of it) after a certain action. I tried to use the Focused property, but it does not seem to work, or the object doesnt have this property. This is on a Web application. Here is the code
reportPage = Aliases.iexplore.IESA;
saveWindow = reportPage.Find("ObjectIdentifier", "MainContent_saveFilterSetDialog_saveDialog", 50, true);
saveWindowNameTextBox = saveWindow.Find("ObjectIdentifier", "*MainContent_*_sfsName", 25, true);
if(saveWindowNameTextBox.Focused == true)
Log.Message("The blinking cursor is inside of the name text box")
else
Log.Error("The blinking cursor is not inside of the name text box")
The logging window says "Waiting for Focused", then it fails and the log says "Unable to find the object with the specified properties"
NOTE: When I inspect this text box object in the object inspector window, "Focused" is not listed in the list of properties.
Is there another way to accomplish this?
I was able to accomplish this using an HTML DOM property activeElement
var actualFocusedElement = Sys.Browser().Page("*BC/Report*").contentDocument.activeElement.id
if(aqString.Contains(actualElement, "saveDialog_tmpl_sfsName", 0, true))
Log.Message("The blinking cursor is inside of the name text box")
else
Log.Error("The blinking cursor is not inside of the name text box")

Resources