如何在颤抖中添加卡片?

时间:2020-05-02 14:08:51

标签: flutter flutter-layout

我正在尝试添加一张卡片。我下面有一段代码,其中有一个脚手架->容器->容器。这包含渐变背景色。当我尝试添加卡片时,渐变背景颜色会消失,或者仅限于页面顶部的一个小容器。

我在哪里添加卡片,以便可以使用全屏背景渐变颜色,并且该卡片是屏幕顶部的小卡片?

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Container(
          child: Container(
            decoration: new BoxDecoration(
              gradient: new LinearGradient(
                begin: Alignment.topCenter,
                end: Alignment.bottomCenter,
                colors: [
                  Color.fromARGB(255, 25, 178, 238),
                  Color.fromARGB(255, 21, 236, 229)
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}

1 个答案:

答案 0 :(得分:0)

DEMO

import tkinter as tk
import tkinter.messagebox

HEIGHT = 600
WIDTH = 600
root = tk.Tk()

canvas = tk.Canvas(root, height=HEIGHT, width=WIDTH)
canvas.pack()

frame = tk.Frame(root, bg="black")
frame.place(relx=0, rely=0, relheight=1, relwidth=1)

label = tk.Label(frame, text="Κυκλοφοριακός Φόρτος", fg="black")
label.place(relwidth=1.0)

label = tk.Label(frame, text="Είδος Οχήματος")
label.place(relx=0, rely=0.1)
label = tk.Label(frame, text="Λεωφορεία")
label.place(relx=0, rely=0.2, relwidth=0.15)
label = tk.Label(frame, text="Ημιφορτηγά")
label.place(relx=0, rely=0.30, relwidth=0.15)
label = tk.Label(frame, text="Φορτηγά")
label.place(relx=0, rely=0.40, relwidth=0.15)
label = tk.Label(frame, text="Συρόμενα")
label.place(relx=0, rely=0.50, relwidth=0.15)
label = tk.Label(frame, text="Άλλα")
label.place(relx=0, rely=0.60, relwidth=0.15)
label = tk.Label(frame, text="Ι.Χ.")
label.place(relx=0, rely=0.70, relwidth=0.15)

label = tk.Label(frame, text="Αριθμός Αξόνων")
label.place(relx=0.2, rely=0.1, relwidth=0.15)
label = tk.Label(frame, text="2 ή 3 άξονες")
label.place(relx=0.2, rely=0.2, relwidth=0.15)
label = tk.Label(frame, text="2 άξονες")
label.place(relx=0.2, rely=0.30, relwidth=0.15)
label = tk.Label(frame, text="3 άξονες")
label.place(relx=0.2, rely=0.40, relwidth=0.15)
label = tk.Label(frame, text="4+ άξονες")
label.place(relx=0.2, rely=0.50, relwidth=0.15)
label = tk.Label(frame, text="2 άξονες")
label.place(relx=0.2, rely=0.60, relwidth=0.15)
label = tk.Label(frame, text="N/A")
label.place(relx=0.2, rely=0.70, relwidth=0.15)

label = tk.Label(frame, text="Συντελεστής Ισοδυναμίας")
label.place(relx=0.4, rely=0.10, relwidth=0.25)
label = tk.Label(frame, text="1.30")
label.place(relx=0.45, rely=0.20, relwidth=0.15)
label = tk.Label(frame, text="0.34")
label.place(relx=0.45, rely=0.30, relwidth=0.15)
label = tk.Label(frame, text="1.50")
label.place(relx=0.45, rely=0.40, relwidth=0.15)
label = tk.Label(frame, text="3.025")
label.place(relx=0.45, rely=0.50, relwidth=0.15)
label = tk.Label(frame, text="0.026")
label.place(relx=0.45, rely=0.60, relwidth=0.15)
label = tk.Label(frame, text="0.00")
label.place(relx=0.45, rely=0.70, relwidth=0.15)

label = tk.Label(frame, text="Αριθμός οχημάτων")
label.place(relx=0.75, rely=0.10, relwidth=0.20)
entry_1 = tk.Entry(frame, bg="white")
entry_1.place(relx=0.75, rely=0.20, relwidth=0.20)
entry_2 = tk.Entry(frame, bg="white")
entry_2.place(relx=0.75, rely=0.30, relwidth=0.20)
entry_3 = tk.Entry(frame, bg="white")
entry_3.place(relx=0.75, rely=0.40, relwidth=0.20)
entry_4 = tk.Entry(frame, bg="white")
entry_4.place(relx=0.75, rely=0.50, relwidth=0.20)
entry_5 = tk.Entry(frame, bg="white")
entry_5.place(relx=0.75, rely=0.60, relwidth=0.20)
entry_6 = tk.Entry(frame, bg="white")
entry_6.place(relx=0.75, rely=0.70, relwidth=0.20)

label = tk.Label(frame, text="Ποσοστό Κυκλοφορίας στη Λωρίδα Μελέτης(ΠΚΛΜ)")
label.place(relx=0, rely=0.8)
entry_7 = tk.Entry(frame)
entry_7.place(relx=0.7, rely=0.8)

label = tk.Label(frame, text="Διάρκεια Σχεδιασμού(σε n έτη)")
label.place(relx=0, rely=0.85)
n = entry_7 = tk.Entry(frame)
n = entry_7.place(relx=0.7, rely=0.85)

label = tk.Label(frame, text="Μέση Ετήσια Αύξηση της Κυκλοφορίας(r σε δεκαδική μορφή)")
label.place(relx=0, rely=0.9)
r = entry_8 = tk.Entry(frame)
r = entry_8.place(relx=0.7, rely=0.9)


def Traffic_Volume():
    tkinter.messagebox.showinfo("Result", "Message goes here")
    float((entry_1 * 1.30 + entry_2 * 0.34 + entry_3 * 1.50 + entry_4 * 3.025 + entry_5 * 0.026 + entry_6 * 0.00) * entry_7 * 365 * ((1 - r) ** n) - 1) / r))
    return


button = tk.Button(root, text="Calculate Traffic Volume", command=Traffic_Volume)
button.pack(side="bottom")

root.mainloop()