-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomment.py
104 lines (88 loc) · 3.97 KB
/
comment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
from tkinter import *
from tkinter.messagebox import *
# from MainPage import *
from tkinter import messagebox
import psycopg2
import etc
from Sql_Search import SqlSearch
import page1
from date import Date
from for_user_id import get_user_id
import etc
import choose
import datetime
from tkinter import ttk
class Comment(object):
def __init__(self, master=None):
self.root = master
winWidth = 650
winHeight = 400
screenWidth = self.root.winfo_screenwidth()
screenHeight = self.root.winfo_screenheight()
x = int((screenWidth - winWidth) / 2)
y = int((screenHeight - winHeight) / 2)
# 设置窗口初始位置在屏幕居中
self.root.geometry("%sx%s+%s+%s" % (winWidth, winHeight, x, y))
# 设置窗口图标
self.root.iconbitmap("./image/3.ico")
# 设置窗口宽高固定
self.root.resizable(0, 0)
self.contents = StringVar()
self.star = StringVar()
self.product_id = StringVar()
self.createPage()
def createPage(self):
self.page = Frame(self.root) # 创建Frame
self.page.pack()
Label(self.page).grid(row=0, stick=W)
Label(self.page, text='评论内容: ').grid(row=1, stick=W, pady=10)
Entry(self.page, textvariable=self.contents).grid(row=1,
column=1,
stick=W)
Label(self.page, text='商品打分: ').grid(row=3, stick=W, pady=10)
self.star.set('5') # 默认选中CCC==combobox.current(2)
values = ['1', '2', '3', '4', '5']
self.combobox = ttk.Combobox(
master=self.page, # 父容器
height=4, # 高度,下拉显示的条目数量
width=8, # 宽度
state='normal', # 设置状态 normal(可选可输入)、readonly(只可选)、 disabled
cursor='arrow', # 鼠标移动时样式 arrow, circle, cross, plus...
font=('', 16), # 字体
textvariable=self.star, # 通过StringVar设置可改变的值
values=values, # 设置下拉框的选项
)
self.combobox.grid(row=3, column=1, stick=W)
Label(self.page, text='评论商品(id): ').grid(row=4, stick=W, pady=10)
Entry(self.page, textvariable=self.product_id).grid(row=4,
column=1,
stick=W)
Button(self.page, text='确认', command=self.Back,
bg='AliceBlue').grid(row=10, column=1, stick=W, columnspan=40)
def Back(self):
user_id = get_user_id()
product_id = self.product_id.get()
contents = self.contents.get()
user_level = 0
like_num = 0
reply_num = 0
star = self.star.get()
comment_date = datetime.datetime.now().strftime("%Y-%m-%d")
try:
#连接数据库需要提供相应的数据库名称、用户名、密码、地址、端口等信息
db = psycopg2.connect(database=etc.database,
user=etc.user,
password=etc.password,
host=etc.host,
port=etc.port)
cursor = db.cursor()
string = "insert into product_comments (release_user, product_id, contents, user_level, like_num, reply_num,star,comment_date) VALUES (%s,%s,'%s',%s,%s, %s, %s,'%s')" % (
user_id, product_id, contents, user_level, like_num, reply_num,
star, comment_date)
cursor.execute(string)
db.commit()
messagebox.showinfo(title='success!', message='添加成功')
except Exception as err:
print(err)
self.page.destroy()
choose.all_comment(self.root)