NetRock6
asked on
Tkinter-Dynamic selection on radio button
Hi...
The following GUI that is used to restore backups for a system.
import Tkinter as tk
root = tk.Tk()
v = tk.IntVar()
v.set(1) # initializing the choice, i.e. Python
backups = [
(200,"WIN_7", "active", 4096, 320, 1),
(201,"WIN_7_sp1", "active", 4096, 320, 2),
(210,"WIN_Java", "inactive", 8019, 8),
(230,"Linux_C78", "active", 4096, 90),
(241,"Linux2_B78", "active", 4096, 80)
]
def ShowChoice():
print(v.get())
tk.Label(root,
text="""Choose a backup
to restore from the list:""",
justify = tk.LEFT,
padx = 20).pack()
for val, backup in enumerate(backups):
tk.Radiobutton(root,
text=backup,
padx = 20,
variable=v,
command=ShowChoice,
value=val).pack(anchor=tk. W)
root.mainloop()
Since the back up list is changing from one system to another, the script needs to be changed to list the available backups. If I run the program 'listbk', it outputs the list as follows:
ID NAME STATUS MEM Disk RANDOMID
100 WIN_7 active 4096 320 1
301 WIN_7_sp1 active 4096 320 2
390 WIN_Java inactive 8019 320 8
480 Linux_C78 active 4096 320 90
541 Linux2_B78 active 4096 500 80
Inside the python script, I am able to run the script using the below command to get the backup list.
from subprocess import call
call(['listbk']).
What is the way to display the available backups for different systems in the GUI.
Thank You for your kind help.
The following GUI that is used to restore backups for a system.
import Tkinter as tk
root = tk.Tk()
v = tk.IntVar()
v.set(1) # initializing the choice, i.e. Python
backups = [
(200,"WIN_7", "active", 4096, 320, 1),
(201,"WIN_7_sp1", "active", 4096, 320, 2),
(210,"WIN_Java", "inactive", 8019, 8),
(230,"Linux_C78", "active", 4096, 90),
(241,"Linux2_B78", "active", 4096, 80)
]
def ShowChoice():
print(v.get())
tk.Label(root,
text="""Choose a backup
to restore from the list:""",
justify = tk.LEFT,
padx = 20).pack()
for val, backup in enumerate(backups):
tk.Radiobutton(root,
text=backup,
padx = 20,
variable=v,
command=ShowChoice,
value=val).pack(anchor=tk.
root.mainloop()
Since the back up list is changing from one system to another, the script needs to be changed to list the available backups. If I run the program 'listbk', it outputs the list as follows:
ID NAME STATUS MEM Disk RANDOMID
100 WIN_7 active 4096 320 1
301 WIN_7_sp1 active 4096 320 2
390 WIN_Java inactive 8019 320 8
480 Linux_C78 active 4096 320 90
541 Linux2_B78 active 4096 500 80
Inside the python script, I am able to run the script using the below command to get the backup list.
from subprocess import call
call(['listbk']).
What is the way to display the available backups for different systems in the GUI.
Thank You for your kind help.
What exactly is 'lstbk'?
ASKER
'lstbk displays the available backup jobs in the system. as you can see in the my question displays the backup jobs.
Is it a shell command?
I'm asking because there are methods that can be used to process the output from something called using the subprocess module.
For example this puts the output from a call to 'mediainfo' into a list.
I'm asking because there are methods that can be used to process the output from something called using the subprocess module.
For example this puts the output from a call to 'mediainfo' into a list.
import subprocess
dim = []
proc = subprocess.Popen('mediainfo --Inform="Video;%Width%x%Height%\\n" /home/saad/Videos/*.*', shell=True,
stdout=subprocess.PIPE)
for line in iter(proc.stdout.readline, ''):
dim.append(line.rstrip('\n'))
print dim
Probably not a good example but hopefully it illustrates the idea.
ASKER
Thank you for your comment.
Yes, It is a shell command.
As, I said in my question i can run it using:
Inside the same python script, I am able to run the script using the below command to get the backup list.
from subprocess import call
call(['listbk']).
After running 'lstbk', i get the following output: (The options are chnaging from system to system, I might have only one line or 5 or 7 lines).
ID NAME STATUS MEM Disk RANDOMID
100 WIN_7 active 4096 320 1
301 WIN_7_sp1 active 4096 320 2
390 WIN_Java inactive 8019 320 8
480 Linux_C78 active 4096 320 90
541 Linux2_B78 active 4096 500 80
Then, how can I display each line in a radiobutton to the users to select, so they can restore the backup they want.
Thanks you for your help....
Yes, It is a shell command.
As, I said in my question i can run it using:
Inside the same python script, I am able to run the script using the below command to get the backup list.
from subprocess import call
call(['listbk']).
After running 'lstbk', i get the following output: (The options are chnaging from system to system, I might have only one line or 5 or 7 lines).
ID NAME STATUS MEM Disk RANDOMID
100 WIN_7 active 4096 320 1
301 WIN_7_sp1 active 4096 320 2
390 WIN_Java inactive 8019 320 8
480 Linux_C78 active 4096 320 90
541 Linux2_B78 active 4096 500 80
Then, how can I display each line in a radiobutton to the users to select, so they can restore the backup they want.
Thanks you for your help....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you so much for your great help.
It works great....
There is only one thing when users select a radiobutton how to store the "ID" number (the first column) into a varaiable, so it can be passed on to the command 'restore' like: restore 301 (to restore the selected backup).
Thank you again.
It works great....
There is only one thing when users select a radiobutton how to store the "ID" number (the first column) into a varaiable, so it can be passed on to the command 'restore' like: restore 301 (to restore the selected backup).
Thank you again.
ASKER
Also, is there a way to display the headings (below line) but not as a radiobutton option:
ID NAME STATUS MEM Disk RANDOMID
Thanks.
ID NAME STATUS MEM Disk RANDOMID
Thanks.
So the first row of the output from 'listbk' is a header row?
ASKER
Yes.. It is a header row as it shown in my question.
Thanks
Thanks
We can remove the 'header' row from the group of radio buttons using this which would go just before the loop that creates the buttons.
To return the text of the selected radio button we can change ShowChoice to this,
backups.pop(0)
If you wanted to display the header you would need code to add a label or something similar, for example.tk.Label(root,text = backups[0]).pack(anchor=tk.N)
To return the text of the selected radio button we can change ShowChoice to this,
def ShowChoice():
print(backups[v.get()])
and you should be able to manipulate the text to get the ID, perhaps something like this.def ShowChoice():
id = backups[v.get()].split()[0]
print(id)
ASKER
Thank you for your great help...
Keep up the good job! ;)
Keep up the good job! ;)