ich schreibe gerade ein Programm, womit man die Zeit wie lange der Rechner schon an ist ermittelt.
Es sieht so aus:
Code: Alles auswählen
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# This program is free software. It comes without any warranty, to
# the extent permitted by applicable law. You can redistribute it
# and/or modify it under the terms of the Do What The Fuck You Want
# To Public License, Version 2, as published by Sam Hocevar. See
# http://sam.zoy.org/wtfpl/COPYING for more details.
"""
uptime.py
~~~~~~~~~
Gibt aus wie lange der Rechner schon an ist
"""
import sys
import re
from PyQt4 import QtGui
class Fenster(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.resize(300, 200)
self.setWindowTitle("Uptime mit Qt")
self.label = QtGui.QLabel(format("Der Rechner ist seit {0} Sekunden an.", uptime()), self)
self.label.move(10, 10)
def uptime():
uptime_datei = open("/proc/uptime", "r")
uptime_inhalt = re.sub(" .*", "", uptime_datei.read()).replace("\n", "")
uptime_datei.close()
return uptime_inhalt
anwendung = QtGui.QApplication(sys.argv)
fenster = Fenster()
fenster.show()
sys.exit(anwendung.exec_())
Das Fenster öffnet sich, und der Text der darin steht ist der:
Weiß jemand woran es liegen könnte? Ich verstehe das irgendwie nicht.Der Rechner ist
Viele Grüße,
Jakob.