पर की आप इस कोड है लगता है, और आप सिर्फ जानना चाहता draw()
लागू करने के लिए कैसे हैं:
def draw(window, string):
window.addstr(0, 0, string)
window.refresh()
draw(window, 'abcd')
draw(window, 'xyz') # oops! prints "xyzd"!
सबसे सरल और "शाप-ish
def draw(window, string):
window.clear() # zap the whole screen
window.addstr(0, 0, string)
window.refresh()
: "समाधान निश्चित रूप से
def draw(window, string):
window.erase() # erase the old contents of the window
window.addstr(0, 0, string)
window.refresh()
आप इस बजाय लिखने के लिए परीक्षा हो सकता है 210
लेकिन नहीं! दोस्ताना दिखने वाले नाम के बावजूद, clear()
वास्तव में केवल when you want the entire screen to get redrawn unconditionally, यानी "झिलमिलाहट" के लिए है। erase()
फ़ंक्शन बिना झिलमिलाहट के सही काम करता है।
फ्रेडेरिक Hamidi सिर्फ वर्तमान विंडो का हिस्सा (रों) मिटा के लिए निम्नलिखित समाधान प्रदान करता है:
def draw(window, string):
window.addstr(0, 0, string)
window.clrtoeol() # clear the rest of the line
window.refresh()
def draw(window, string):
window.addstr(0, 0, string)
window.clrtobot() # clear the rest of the line AND the lines below this line
window.refresh()
एक छोटा और शुद्ध पायथन विकल्प होगा
def draw(window, string):
window.addstr(0, 0, '%-10s' % string) # overwrite the old stuff with spaces
window.refresh()
यह पहले किया जा सकता है 'ताज़ा करें' या उसके बाद? – Pablo
'रीफ्रेश() 'से पहले और' addstr()' के बाद (इन सभी परिचालनों को केवल "वर्चुअल" शाप स्क्रीन को अपडेट करें जब तक कि 'रीफ्रेश()' कहा जाता है)। –