テキストファイルを読み込み、単純な時計アプリケーションでスケジュールの一部として使用する辞書に設定する機能を終了しました。変数をfuction呼び出しに割り当てるときにdictを呼び出すことはできません
schedule = schedule()
print(schedule)
私は、アプリケーション内の同じ方法でそれを呼び出すときしかし、私はそれを呼び出すことはできませんどのように来る、「dictのは、呼び出し可能なエラーではありません」を取得:別々のスクリプト内や使用と呼ばれる独自の私のアプリケーション内で同じ方法ですか?
#!/usr/bin/python3
# Full screen clock
import tkinter as tk
import time
def schedule(): # this function
flag = False
schedule = dict()
times = []
days_of_the_week = ["Monday", "Tuesday", "Wednesday",
"Thursday", "Friday",
"Saturday", "Sunday"]
with open("/home/pi/Desktop/schedule.txt", 'r') as f:
for line in f:
s = line.strip()
if s == '':
continue
elif s in days_of_the_week:
day = s
times.clear()
else:
times.append(s)
schedule[day] = times[:]
return schedule
root = tk.Tk()
root.attributes("-fullscreen", True)
root.configure(background='black')
frame = tk.Frame(root)
frame.configure(background='black')
frame.pack(expand=tk.TRUE)
schedule = schedule() # function is called here
clock_lt = tk.Label(frame,
font=('Serene MTC', 230),
fg='#FF8000',
bg='black')
clock_lt.pack()
date_etc = tk.Label(frame,
font=('Ariel', 50),
fg='#FF8000',
bg='black')
date_etc.pack()
date_iso = tk.Label(frame,
font=('Ariel', 50),
fg='#FF8000',
bg='black')
date_iso.pack()
running_time = tk.Label(frame,
justify=tk.LEFT,
font=('Ariel', 15),
fg='#CDAF90',
bg='black')
running_time.pack()
def tick():
schedule = schedule()
time1 = ''
time2 = time.strftime('%H:%M')
date_etc_txt = "%s" % (time.strftime('%A')).upper()
date_iso_txt = time.strftime('%d-%B-%Y').upper()
today = date_etc_txt.title()
if time2 != time1:
time1 = time2
clock_lt.config(text=time2)
date_etc.config(text=date_etc_txt)
date_iso.config(text=date_iso_txt)
running_time.config(text=day_schedule[today])
clock_lt.after(20, tick)
tick()
root.mainloop()
ここでは何が違うのですか?残念ながら、私はこのエラーを乗り越えることができないとして、このコードは完全に機能するようになりましたかどうか知りませんが、行をコメントアウトする場合:
schedule = schedule()
は、それが正常に動作します。ここで
は、私が使用しているテストデータである:私は間違っ
Friday
08:00 - 08:30 Morning briefing
09:15 - 10:30 Shakedown
Saturday
08:00 - 08:30 Morning briefing
09:00 - 10:00 Prep and Warm Up
Sunday
08:00 - 08:30 Morning briefing
09:00 - 10:00 Prep and Warm Up
何をしてくださいでしょうか?
ので、私はday_scheduleに変数名の名前を変更したと私は同じ結果を取得していますトレースバック(最新の呼び出しの最後):? ファイル「./fsclock.py」、ライン82、 ダニ() ファイル」で./fsclock.py "、line 65、tick in day_schedule = schedule() TypeError: 'dict'オブジェクトが呼び出せません –
iFunction
これはIDLE(または実行中のPythonインタープリタを保持する別のIDE)で実行していますか?その場合はインタープリタを再起動する必要があります。 –
と 'schedule = schedule()'という行がコード内で2回表示されます。 'tick()'関数の2回目です。 –