python - Opening a specific file depending on variables -
okay, gui want read file depending on variable result is. i'll try explain in more detail.
so file takes input drop down menu. option user picks decide file read. file read appended array, put drop down menu.
i want know if possible. parts of code down below.
earlier drop down menu:
weapon.set('sword') choices = ['sword', 'bow', 'katana'] self.weaponmenu = optionmenu(self,weapon, *choices) self.weaponmenu.grid(row =2, column = 2)
reading file:
self.moves = label(self, text = "move") self.moves.grid(row = 9, column = 1,) move = stringvar() weapon = open("%d.txt" %(self.weaponmenu.get()),"r") #reads weapon file moves = [] line in weapon: moves.append(line) self.movesmenu = optionmenu(self, move, *moves) self.movesmenu.grid(row =10, column = 1)
this tried do, unable work. if statements instead probably, want know if method i'm trying can work or if there else can achieve same results.
i hope understood wrote , in advance help! hope did right, i'm still new stackoverflow.
when try execute file, following error message:
i following error message:
traceback (most recent call last): file "c:\python27\mh4udamagewindow.py", line 88, in <module> app = application(root) file "c:\python27\mh4udamagewindow.py", line 10, in __init__ self.create_widget() file "c:\python27\mh4udamagewindow.py", line 67, in create_widget weapon = open("%d.txt" % (self.weaponmenu.get()),"r") #reads weapon file attributeerror: optionmenu instance has no attribute 'get' >>>
use variable set optionmenu
(weapon
) , not widget itself:
weapon = open("%s.txt" % (weapon.get()),"r") #reads weapon file
if it's not available in scope read file, add self
.
Comments
Post a Comment