我试图在eclipse上使用Tkinter,它适用于这样的短代码:
from tkinter import *
root = Tk()
mainloop()
此代码适用于eclipse,但这个代码不适用:
from tkinter import Tk, Canvas, HIDDEN, NORMAL
root = Tk()
root.title('Snap')
c = Canvas(root, width=400, height=400)
shapes = []
circle = c.create_oval(35, 20, 365, 350, outline='black', fill='black',
state=HIDDEN)
shapes.append(circle)
circle = c.create_oval(35, 20, 365, 350, outline='red', fill='red',
state=HIDDEN)
shapes.append(circle)
circle = c.create_oval(35, 20, 365, 350, outline='green', fill='green',
state=HIDDEN)
shapes.append(circle)
circle = c.create_oval(35, 20, 365, 350, outline='blue', fill='blue',
state=NORMAL)
shapes.append(circle)
c.pack()
此代码应该显示一个窗口并且上面有一个蓝色圆圈,但我尝试运行它但没有任何反复发生。
答案 0 :(得分:1)
最后添加<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/tools"
android:id="@+id/my_cardview"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/cardview_titleA"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/image_pictogram"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/cardview_titleB"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</android.support.v7.widget.CardView>
,如下所示:
root.mainloop()
或者在导入中包含from tkinter import Tk, Canvas, HIDDEN, NORMAL
root = Tk()
root.title('Snap')
c = Canvas(root, width=400, height=400)
shapes = []
circle = c.create_oval(35, 20, 365, 350, outline='black', fill='black', state=HIDDEN)
shapes.append(circle)
circle = c.create_oval(35, 20, 365, 350, outline='red', fill='red', state=HIDDEN)
shapes.append(circle)
circle = c.create_oval(35, 20, 365, 350, outline='green', fill='green', state=HIDDEN)
shapes.append(circle)
circle = c.create_oval(35, 20, 365, 350, outline='blue', fill='blue', state=NORMAL)
shapes.append(circle)
c.pack()
root.mainloop()
并运行mainloop
而不是mainloop()