Skip to content

Latest commit

 

History

History
58 lines (39 loc) · 1.02 KB

W3.md

File metadata and controls

58 lines (39 loc) · 1.02 KB

1. File I/O

import os

# classmates
new_file_path = 'D:\lenovo\下载\大数据与人工智能\myclassmates.txt'
with open(new_file_path, 'w') as newfile:
    newfile.write('hsn sl, hyj sl, lxy tm')
with open(new_file_path, 'a+') as newfile:
    newfile.write('hsn sl, hyj sl, lxy tm')   
import random

with open('data.txt', 'w') as myfile:
    for i in range(20):
        myfile.write(str(random.randint(1,100))+' ')

data=list()
for i in range(20):
    data.append(random.randint(1,100))
print(data)
[23, 57, 34, 65, 55, 37, 90, 6, 41, 73, 34, 3, 79, 33, 49, 45, 85, 2, 12, 66]

2. 模块

3. Tkinter GUI

from tkinter import *

def Call():
    msg = Label(window, text = 'You pressed the button')
    msg.place(x=30, y=50)
    button["bg"] = "blue"
    button["fg"] = "white"

window = Tk()
window.geometry("200x100")
button = Button(text = "Press me", command = Call)
button.place(x=30, y=20, width=120, height=25)
window.mainloop()
def click():